Simple WINSOCK API SMTP Letter Sender.

xiaoxiao2021-03-06  50

This is a simple program written in front of the tutorial in front of the previous translation. I have written very early before, simplify, so it is easier to learn. First let's take a look at the letter from the NC simulation. D: / hacker> nc smtp.163.com 25220 Coremail SMTP (Anti Spam) System (163com [20030606]) EHLO 123250-192.168.1.205250-PIPELINING250-ETRN250-AUTH LOGIN PLAIN NTLM250-AUTH = LOGIN PLAIN NTLM250 8BITMIMEAUTH LOGIN334 VXNlcm5hbWU6 * **************; username / base64 334 ugfzc3dvcmq6 ****************; Password / Base64235 Authentication SuccessFulmail from: 250 Okrcpt TO: 250 Okdata354 End Data with . Date: Fri, 2 Jul 2004 15:20:29 0800From: "Excuseser3" < Excuseser3@163.com> to: "Excuseser" Subject: x-mailer: foxmail 5.0 [cn] mime-version: 1.0content-type: text / plain; charSet = "gb2312" Content-Transfer -Encoding: base64ZXhjdXNlc2Vyo6zE rrDo6ENCg0KCSAgICAgICAgICAgIDEyMzEyMzIxMzEyMw0KDQqhoaGhoaGhoaGhoaGhoaGh1sINCsDxo6ENCiAJCQkJDQoNCqGhoaGhoaGhoaGhoaGhoaFleGN1c2VzZXIzDQqhoaGhoaGhoaGhoaGhoaGhZXhjdXNlc2VyM0AxNjMuY29tDQqhoaGhoaGhoaGhoaGhoaGhoaGhoTIwMDQtMDctMDINCg ==

. 250 ok: queued as mgch9vcq5ueafj9.1quit221 bye

D: / Hacker> OK, is it very eye? After establishing a connection with the SMTP server: 1, send helo *** 2, send auth3, send username (encrypted with base64 encryption) 4, send Password (encrypted with base64) 5, you can send content after confirmation. (Whether encryption will see yourself.) 6, if there is an attachment, use Base64 encryption. 7, quit is simple? Network programming is really just sending and receiving information! ! ! ? ? Programming is implemented.

001 001.const003 MaxNum EQU 2048004 005 .DATA006 SZFMT DB "% D", 0007; Szerrsend DB "Send Failure!", 0008 SzuserPassCheck DB "235", 0009 Szhelofmt DB "EHLO% S", 13, 10, 0010 Szauth DB "Auth login", 13, 10, 0011 szusernamefmt db "% s", 13, 10, 0012 Szpasswordfmt DB "% s", 13, 10, 0013 014; SZFMT1 DB "Mail from: <% s>", 13, 10015 016 Szheaderfmt DB "Mail from: <% s>", 13, 10017 DB "RCPT TO: <% S>", 13, 10, 0018 019 SZBody1FMT DB "DATA", 13, 10020 DB "from:% S < % s>, 13, 10021 dB "to: <% s>", 13, 10022 dB "Subject:% s" 023 dB "x-mailer: xmail 0.8 [cn]", 13, 10024 dB "Welcome to HTTP : //exc.yeah.net ", 13, 10025 DB "MIME-VERSION: 1.0", 13, 10026 DB "Content-Type: Text / Plain; Charset = GB2312", 13, 10027 DB "Content-Transfer-Encoding: 8bit", 13, 10, 13, 10028 DB " % s ", 13, 10, 13, 10, 029 030 Comment ~ 031 Szattachmentfmt DB" Content-Type: Application / OcTet-Stream; Name =% S ", 13, 10032 DB" Content-Disposition: attachment; filename = % s "

13, 10033 DB "Content-Transfer-Encoding: 8bit", 13, 10, 13, 10034 DB "% S", 13, 10, 13, 10, 0035 ~ 036 SZBODY3 DB "Content-Type: Application / OcTet Stream; Name = ", 0037 SZBody4 DB 13, 10, 0038 SZBody5 DB" Content-Disposition: attachment; filename = ", 0039 SZBody6 DB 13, 10, 0040 SZBody7 DB" Content-Transfer-Encoding: Base64 ", 13, 10 , 13, 10, 10, 13, 10, 0042 SZBODYEND DB "" 043 DB 13, 10, ".", 13, 10, 0044 Szquit DB "Quit", 13, 10, 0045; DWSIZE DD 100H046 SZFILTERSTRING DB "All Files", 0, "*. *", 0, 0047 SzmyTIL DB "Please open a file as an attachment!", 0048 reply_val dd 0049 WSAData Wsadata <> 050 SIN SOC Kaddr_in <> 051 052 053.DATA? 054 HSSMTPSERVER DB 255 DUP (?) 056 SZFileName DB 256 DUP (?) 057 SZBuffer DB MAXNUM DUP (?) 058 SZBUF1 DB MAXNUM DUP (?) 059 SZBUF2 DB MAXNUM DUP (?) 060 SZBUF3 DB MAXNUM DUP (?) 061 Szhelo DB MAXNUM DUP (?) 062 Szusername DB MAXNUM DUP (?) 063 Szpassword DB MaxNum DUP (?) 064 Szheader DB MaxNum DUP (?) 065;

szContent db MAXFILESIZE 2048 dup 066 067 068 .code069 include _strstr.asm070 include _Base64.asm071 072 _Smtp proc 073 LOCAL hFile (?): HANDLE074 LOCAL hMapFile: HANDLE075 LOCAL dwFileSize: DWORD076 LOCAL pMemory: DWORD077 LOCAL pContent: DWORD078 LOCAL pFileContent: DWORD079 080 081 Print "is issued ........." 082 Invoke Wsastartup, 0002H, addr wsadata083 .IF EAX! = Null084 print "Load Winsock.dll error" 085 .lse086 invoke socket, AF_INET, SOCK_STREAM, 0087 .IF EAX == INVALID_SOCKET088 print "error establishing socket!" 089 .else090 mov hSocket, eax091 mov sin.sin_family, AF_INET092 invoke htons, 25093 mov sin.sin_port, ax094 095 invoke lstrcpy, addr szSmtpServer, addr sz1096 invoke gethostbyname, addr szSmtpServer097 mov eax, [ EAX 12] 098 MOV EAX, [EAX] 099 MOV EAX, [EAX] 100 MOV SIN.SIN_ADDR, EAX 101 Invoke Connect, HSocket, Addr Sin, SIZEOF SIN102. IF Eax <0103 Print "When connecting!" 104 .lse105 Invoke RTLZERMEMORY, Addr Szbuffer, Maxnum106 Invoke RTLZERMEMEMORY, ADDR SZBUF1, MAXNUM107 INVOKE RTLZERMEMORY, ADDR SZBUF2, MAXNUM108 Invoke RTLZERMEMORY, ADDR SZBUF3, MAXNUM109 110; Send Helo:

111 invoke wsprintf, addr szHelo, addr szHeloFmt, addr szSmtpServer112 invoke lstrlen, addr szHelo113 invoke send, hSocket, addr szHelo, eax, 0114 invoke RtlZeroMemory, addr szBuffer, MAXNUM115 116; sending Auth: 117 invoke lstrlen, addr szAuth118 invoke send, hSocket , addr szAuth, eax, 0119 120; transmitting username: 121 invoke lstrcpy, addr szBuffer, addr sz2122 invoke lstrlen, addr szBuffer123 invoke Base64Encode, addr szBuffer, addr szBuf1, eax124 invoke wsprintf, addr szUsername, addr szUsernameFmt, addr szBuf1125 invoke lstrlen, Addr Szusername126 Invoke Send, HSocket, Addr Szusername, Eax, 0127 Invoke RTLZERMEMORY, ADDR SZBUF1, MAXNUM128 Invoke RTLZERMEMORY, ADDR SZBUFFER, MAXNUM129 130; Send Password: 131 invoke lstrcpy, addr szBuffer, addr sz3132 invoke lstrlen, addr szBuffer133 invoke Base64Encode, addr szBuffer, addr szBuf1, eax134 invoke wsprintf, addr szPassword, addr szPasswordFmt, addr szBuf1135 invoke lstrlen, addr szPassword136 invoke send, hSocket, addr szPassword, eax, 0137 invoke RtlZeroMemory, addr szBuf1, MAXNUM138 invoke RtlZeroMemory, addr szBuffer, MAXNUM139 140; get message returned by the server: 141 invoke Sleep, 1000 142 invoke recv, hSocket, addr szBuffer, MAXNUM, 0143; if the username / password is correct:

144 invoke strstr, addr szBuffer, addr szUserPassCheck, 1 145 .if eax == 0 146 print "username / password authentication fails!" 147 .else148 invoke RtlZeroMemory, addr szBuffer, MAXNUM149; send Header: 150 invoke lstrcpy, addr szBuf1, addr sz2151 invoke lstrcpy, addr szBuf2, addr sz5152 invoke wsprintf, addr szHeader, addr szHeaderFmt, addr szBuf1, addr szBuf2153 invoke lstrlen, addr szHeader154 invoke send, hSocket, addr szHeader, eax, 0155 156; allocate memory: 157; invoke LocalAlloc, LPTR, DWSITUALLOC, 0,65535, MEM_RESERVE MEM_COMMIT, PAGE_READWRITE159 MOV PCONTENT, EAX160 161 Invoke Localalloc, LPTR, 10000000162 MOV PCONTENT, EAX163 ; Send Body1: 164 invoke lstrcpy, addr szBuf3, addr sz6 165 invoke lstrcpy, addr szBuffer, addr sz7 166 invoke wsprintf, pContent, addr szBody1Fmt, addr sz0, addr sz4, addr szBuf2, addr szBuf3, addr szBuffer167 invoke RtlZeroMemory, addr szBuffer , MaxNum 168 Invoke LSTRCAT, PCONTENT, ADDR SZBODYEND169 170; Send Content:

转载请注明原文地址:https://www.9cbs.com/read-81632.html

New Post(0)