SHARE
TWEET

Untitled

a guest Sep 13th, 2017 157 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;compile with:
  2. ;   NASMW.EXE -fobj net.asm
  3. ;link with:
  4. ;   ALINK.EXE net.obj -c -oPE -subsys console
  5.  
  6. %include "c:\w32nasm\inc\win32n.inc"
  7.  
  8.  
  9. EXTERN __getmainargs
  10. IMPORT __getmainargs Msvcrt.dll
  11. EXTERN ExitProcess
  12. IMPORT ExitProcess kernel32.dll
  13. EXTERN GetCommandLineW
  14. IMPORT GetCommandLineW kernel32.dll
  15. EXTERN printf
  16. IMPORT printf Msvcrt.dll
  17. EXTERN CommandLineToArgvW
  18. IMPORT CommandLineToArgvW Shell32.dll
  19. EXTERN WSAStartup
  20. IMPORT WSAStartup Ws2_32.dll
  21. EXTERN WSAGetLastError
  22. IMPORT WSAGetLastError Ws2_32.dll
  23. EXTERN socket
  24. IMPORT socket Ws2_32.dll
  25. EXTERN htons
  26. IMPORT htons Ws2_32.dll
  27. EXTERN htonl
  28. IMPORT htonl Ws2_32.dll
  29. EXTERN inet_addr
  30. IMPORT inet_addr Ws2_32.dll
  31. EXTERN closesocket
  32. IMPORT closesocket Ws2_32.dll
  33. EXTERN WSACleanup
  34. IMPORT WSACleanup  Ws2_32.dll
  35. EXTERN connect
  36. IMPORT connect Ws2_32.dll
  37. EXTERN send
  38. IMPORT send Ws2_32.dll
  39. EXTERN recv
  40. IMPORT recv Ws2_32.dll
  41. EXTERN strtol
  42. IMPORT strtol Msvcrt.dll
  43. EXTERN ExitProcess
  44. IMPORT ExitProcess kernel32.dll
  45. EXTERN memcpy
  46. IMPORT memcpy Msvcrt.dll
  47. EXTERN memset
  48. IMPORT memset Msvcrt.dll
  49. EXTERN atoi
  50. IMPORT atoi Msvcrt.dll
  51. EXTERN bind
  52. IMPORT bind Ws2_32.dll
  53. EXTERN listen
  54. IMPORT listen Ws2_32.dll
  55. EXTERN accept
  56. IMPORT accept Ws2_32.dll
  57.  
  58.  
  59. STRUC WSADATA
  60.   wVersion       resw 1
  61.   wHighVersion   resw 1
  62.   szDescription  resb 256+1
  63.   szSystemStatus resb 128+1
  64.   iMaxSockets    resw 1
  65.   iMaxUdpDg      resw 1
  66.   lpVendorInfo   resw 1
  67. ENDSTRUC
  68.  
  69. STRUC SOCKADDR_IN
  70.   sin_family        resw    1
  71.   sin_port          resw    1
  72.   sin_addr          resb    4
  73.   sin_zero          resb    8
  74. ENDSTRUC
  75.  
  76.  
  77. segment .data USE32
  78.  
  79.     CR    equ 0Dh
  80.     LF    equ 0Ah
  81.  
  82.     wsaData     dd  WSAdata                ; pointer to structure
  83.     sockAddr    dd  SOCKADDR_IN            ; pointer to structure
  84.     hSocket resd 1
  85.     cSocket resd 1
  86.  
  87.     msginitialized db " starting connection",CR,LF,0
  88.  
  89. SECTION CODE USE32 CLASS=CODE
  90.  
  91. ..start:
  92.  
  93.  
  94. ;-----------------------------------------
  95. ;initialize the winsock library
  96. ;-----------------------------------------
  97.  
  98.     push dword wsaData
  99.     push dword 2
  100.     call [WSAStartup]
  101.  
  102.  
  103.  
  104. ;--------------------------------
  105. ;check winsock version
  106. ;--------------------------------
  107.  
  108. _sockversion:
  109.     cmp byte[wsaData+wVersion],2
  110.  
  111.  
  112.  
  113. ;-----------------------
  114. ;Create a socket
  115. ;-----------------------
  116.  
  117. __createsocket:
  118.  
  119.  
  120.     mov [sockAddr+sin_family], dword 2
  121.     mov [sockAddr+sin_addr],dword 0
  122.     mov [sockAddr+sin_port],word 0xaaa
  123.  
  124.     push dword IPPROTO_TCP
  125.     push dword SOCK_STREAM
  126.     push dword AF_INET
  127.     call [socket]
  128.  
  129.     mov [hSocket],eax
  130.  
  131.  
  132.     push dword 0x10
  133.     push dword sockAddr
  134.     push dword [hSocket]
  135.     call [bind]
  136.  
  137.  
  138.     push dword 0x5
  139.     push dword [hSocket]
  140.     call [listen]
  141.    
  142. forever:
  143.  
  144.     push dword 0x0
  145.     push dword 0x0
  146.     push dword [hSocket]
  147.     call [accept]
  148.     mov [cSocket], eax
  149.  
  150.     jmp forever
  151.  
  152.  
  153. _end:
  154.  
  155.     push dword[cSocket]
  156.     call [closesocket]
  157.  
  158.     push dword[hSocket]
  159.     call[closesocket]
  160.  
  161.  
  162.  
  163.     call[WSACleanup]
  164.  
  165. _finished:
  166.     xor eax,eax
  167.     call[ExitProcess]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top