Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "tests.h"
- void TestSMTPErrors()
- {
- #define ATTACHMENT 1
- #define HTML 1
- #define BAD_CONTENT 0
- /*
- RCPT TO:<andreas.jacks@labmed.ki.se>
- 554 5.7.1 Service unavailable; Client host [hiding.my.ip.sorry] blocked using rkxxxxxxxxxxxxxxxxxxxxxje.zen.dq.spamhaus.net; http://www.spamhaus.org/query/bl?ip=hiding.my.ip.sorry
- --
- MAIL FROM:<info@irubybestclub.com>
- 550 DY-001 (SNT0-MC4-F41) Unfortunately, messages from hiding.my.ip.sorry weren't sent. Please contact your Internet service provider. You can tell them that Hotmail does not relay dynamically-assigned IP ranges. You can also refer your provider to http://mail.live.com/mail/troubleshooting.aspx#errors.
- ---
- RCPT TO:<bombproof@emirates.net.ae>
- 554 5.7.1 Blocked by Reputation Enabled Defense: The Ip address is blacklisted, for inquiry please e-mail: abuse@eim.ae or visit http://bsn.borderware.com/lookup?ip=hiding.my.ip.sorry&u=89xxxxxxxxxxda52&d=4c8xxxxxxxxxxx2
- ---
- */
- SMTP smtp;
- #if 1
- smtp.connect("localhost", "[127.0.0.1]", false);
- #else
- smtp.connect("mx-ha02.web.de", "[127.0.0.1]", false);
- #endif
- if(!smtp.is_connected())
- {
- // Err: 2 Stat: 1 Errorcode: "500 Permission denied (Not authorized by POP3)"
- /*
- Microb -
- "554-web.de (mxweb105) Nemesis ESMTP Service not available
- 554-No SMTP service
- 554-IP address is black listed.
- 554 For explanation visit http://postmaster.web.de/error-messages?ip=hiding.my.ip.sorry"
- */
- /*
- facebook:
- 554 5.7.1 POL-P1 http://spamhaus.org/query/bl?ip=...
- */
- printf("After sending with bad content. Err: %i. Stat: %i\n", smtp.get_error(), smtp.get_status());
- return;
- }
- #if 0
- // Err: 6 Stat: 3
- smtp.authenticate("not_a_user", "ad");
- printf("Wrong creds. Err: %i. Stat: %i\n", smtp.GetError(), smtp.GetStatus());
- #endif
- #if 0
- // Err: X Stat: X
- smtp.send_command("DATA\r\n");
- printf("After DATA out of order. Err: %i. Stat: %i\n", smtp.GetError(), smtp.GetStatus());
- #endif
- #if 0
- /*RCPT TO:<bombotha@uptownprimary.ae>
- 550 5.1.1 <bombotha@uptownprimary.ae>... User unknown*/
- // Err: 10 Stat: 5 Errorcode: "550 Address <a@localhost> not known here."
- smtp.AddAddress("a@localhost", smtp.TO);
- // Err: 10 Stat: 5 Errorcode: "553 We do not relay without RFC2554 Auth."
- // Err: 10 Stat: 5 Errorcode: "550 Permission denied for relaying "
- smtp.AddAddress("admin@ende.de", smtp.TO);
- // Err: 0 Stat: 7 Errc: "555 Message rejected: site policy requires all mail to have a 'Date' field"
- #endif
- SMTP::Address addr;
- addr.a = "test@localhost";
- // addr.friendlyName = "My dear friend";
- // addr.a = "newuser@localhost";
- // addr.a = "newuser@system.mail"; // WinWebMail
- // addr.a = "test@gmail.com";
- smtp.add_address(addr, smtp.TO);
- //[6256] <506 failed MAIL FROM verification with the authentication data.
- // addr.a = "bill.gates@microsoft.com";
- addr.friendlyName = "Your dear friend";
- smtp.add_address(addr, smtp.FROM);
- #if ATTACHMENT
- HANDLE f = CreateFile(TEXT("C:\\xampp\\htdocs\\Pharmacy\\app\\webroot\\img\\header\\logo.png"), GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if(NULL == f || INVALID_HANDLE_VALUE == f)
- return;
- DWORD size = GetFileSize(f, NULL), read;
- unsigned char* content = new unsigned char[size];
- ReadFile(f, content, size, &read, NULL);
- CloseHandle(f);
- smtp.add_attachment(content, size, "logo.png", "image/png");
- delete[] content;
- #endif
- #if BAD_CONTENT
- // Mercury drops connection when subject = "%viagra%" -> Err: 14 Stat: 7
- smtp.set_subject("Buy Viagra");
- smtp.set_message("Buy viagra.");
- #if HTML
- smtp.set_HTML_message("<a href=\"http://zief.pl/store/\">Canadian Pharmacy</a>");
- #endif
- smtp.send();
- #else
- std::string tmp;
- add_int_to_string(tmp, GetTickCount());
- smtp.set_subject(tmp);
- smtp.set_message("Totally legit, unsuspcious content");
- #if HTML
- smtp.set_HTML_message("<a href=\"http://google.com/\">Cool search engien</a>");
- #endif
- smtp.send();
- #endif
- printf("After sending with bad content. Err: %i. Stat: %i\n", smtp.get_error(), smtp.get_status());
- }
- void TestBlacklist()
- {
- char ownIP[16] = {0};
- //get_public_IP(ownIP);
- strncpy_s(ownIP, 16, "68.235.35.131", 15);
- RBL* rbl = new RBL();
- if(rbl->check(ownIP))
- printf("In some kind of blacklist\n");
- }
- void TestSMTPS(std::string server)
- {
- SMTP smtp;
- char localIP[IP4_ADDRESS_STRING_BUFFER_LENGTH + 2] = {0}; // 2 == strlen("[]")
- get_HELO_name(localIP);
- smtp.connect(server, localIP, false);
- if(!smtp.is_connected())
- return;
- if(!smtp.is_TLS_possible())
- return;
- puts("Ready for SSL");
- if(!smtp.switch_to_TLS())
- puts("Couldn't switch");
- }
- enum TESTSEND_ENUM
- {
- SENT = 0,
- LOGIN_SUCCESS = 1,
- LOGIN_POSSIBLE = 2,
- SERVER_FOUND = 3,
- SERVER_SUCKS = 4
- };
- int TestSendHelper(std::string server, std::string user, std::string password)
- {
- SMTP smtp;
- char localIP[IP4_ADDRESS_STRING_BUFFER_LENGTH + 2] = {0}; // 2 == strlen("[]")
- std::vector<MX_Information> mxServers;
- std::string subDomains[] = {
- std::string(""),
- std::string("smtp."),
- std::string("mail."),
- std::string("smtp.mail."),
- std::string("securesmtp."),
- std::string("mx."), };
- // To make the relation debug message <=> socket operation more clear
- OutputDebugStringA(server.c_str());
- get_HELO_name(localIP);
- // Connect Original, smtp., mail., mx servers
- for(unsigned int i = 0; i < _countof(subDomains); i++)
- {
- if(smtp.connect(subDomains[i] + server, localIP, true))
- break;
- if(smtp.connect(subDomains[i] + server, localIP, false))
- break;
- }
- // Last Measure: Try the MX servers
- if(!smtp.is_connected())
- {
- if(!GetMXServers(server, mxServers))
- return SERVER_SUCKS;
- if(!smtp.connect(mxServers, localIP, false))
- return SERVER_SUCKS;
- }
- smtp.print_supported_functions();
- // If authentication isn't available switch to encrypted Connection
- if(!smtp.is_login_possible())
- {
- if(!smtp.is_TLS_possible())
- return SERVER_FOUND;
- if(!smtp.switch_to_TLS())
- return SERVER_FOUND;
- if(!smtp.is_login_possible())
- return SERVER_FOUND;
- }
- smtp.print_supported_functions();
- if(!smtp.authenticate(user, password))
- {
- printf("Can't login: %s %s", smtp.get_reply_code(), smtp.get_reply_message());
- return LOGIN_POSSIBLE;
- }
- SMTP::Address addr;
- addr.a = "test@gmail.com";
- smtp.add_address(addr, smtp.TO);
- addr.a = (std::string::npos == user.find("@") ? (user + "@" + server) : user);
- smtp.add_address(addr, smtp.FROM);
- smtp.set_subject("Testmail #2");
- smtp.set_message("This is another automatically generated test mail\nPlease do reply -- just kidding");
- bool sentSuccess = smtp.send();
- if(!sentSuccess)
- {
- printf("%i:%i. %s %s\n", smtp.get_error(), smtp.get_status(), smtp.get_reply_code(), smtp.get_reply_message());
- }
- return (sentSuccess ? SENT : LOGIN_SUCCESS);
- }
- void TestSend()
- {
- //#define SKIP
- const char* credentials[][3] = {
- // Freemail providers
- #ifndef SKIP
- {"gmail.com", "a", "sbawks123456"},
- {"smtp.gmail.com", "a", "02121984"},
- {"aol.com", "a", "Deninho"},
- {"live.com", "a@hotmail.com", "lairenita1"},
- {"web.de", "a@web.de", "24121996"},
- {"mail.ru", "a@mail.ru", "272614m"},
- {"lycos.com", "a", "fkosdksdosd"},
- {"yahoo.co.uk", "a", "230203241107"},
- #endif
- {"latinmail.com", "a", "dsksd$)%"},
- {"qq.com", "a", "aaaaaa"},
- {"india.com", "a", "fkldf0%$()="},
- {"rambler.ru", "aaaaaa", "Complex123"},
- // ISP
- #ifndef SKIP
- {"orange.fr", "a@orange.fr", "6heyt9w"},
- {"mail.t-online.hu", "a", "A44XTae4tm"},
- {"biglobe.ne.jp", "a@bma.biglobe.ne.jp", "scde7r8e"},
- {"home.nl", "a", "screen50"},
- {"arcor.de", "a", "dfjkldfsdkg054"},
- {"comcast.net", "a", "test"},
- {"t-online.de", "a", "test"},
- #endif
- {"btinternet.com", "a", "test"},
- {"verizon.com", "a", "test"},
- {"o2.de", "a", "test"},
- // Other shit
- {"facebook.com", "a", "palm0609"},
- {"guitar.ocn.ne.jp", "a", "masako0"},
- {"thebartonfamily.co.uk", "a@talktalk.net", "ribange"},
- {"albatrossthai.com", "a", "#S3Q5H2#"},
- #ifndef SKIP
- {"beacontex.com", "a@beacontex.com", "12345-8633000"},
- #endif
- };
- int sent = 0,
- workingCredentials = 0,
- serversWithLoginFunc = 0,
- connectedSuccessfully = 0;
- for(unsigned int i = 0; i < _countof(credentials); i++)
- {
- int temp = TestSendHelper(credentials[i][0], credentials[i][1], credentials[i][2]);
- printf("%i <== %s:%s@%s\n", temp, credentials[i][1], credentials[i][2], credentials[i][0]);
- switch(temp)
- {
- case SENT:
- sent++;
- case LOGIN_SUCCESS:
- workingCredentials++;
- case LOGIN_POSSIBLE:
- serversWithLoginFunc++;
- case SERVER_FOUND:
- connectedSuccessfully++;
- break;
- }
- }
- printf("Found: %f\n"
- "Login possible: %f\n"
- "Login succes: %f\n"
- "Sent: %f\n",
- ((float)connectedSuccessfully / (float)_countof(credentials)),
- ((float)serversWithLoginFunc / (float)_countof(credentials)),
- ((float)workingCredentials / (float)_countof(credentials)),
- ((float)sent / (float)_countof(credentials)));
- }
- int TestMxRecordConnectWithAuth(std::vector<MX_Information> mxServers)
- {
- SMTP smtp;
- if(smtp.connect(mxServers, "[127.0.0.1]", true))
- return 0;
- return 1;
- }
- int TestMxRecordConnectWithoutAuth(std::vector<MX_Information> mxServers)
- {
- SMTP smtp;
- if(smtp.connect(mxServers, "[127.0.0.1]", false))
- return 1;
- return 0;
- }
- // Runs longer than 5min 12sec
- void TestMxRecord()
- {
- const char* address[] = {
- "8.35.201.114", // Virustotal
- "156.33.241.5", // US Goverment
- "46.115.114.168", // E-Plus Cellphone Internet
- "115.69.254.225",
- "c-65-34-208-5.hsd1.fl.comcast.net",
- "d72-39-140-144.home1.cgocable.net",
- "75-171-211-203.hlrn.qwest.net",
- "cpe-76-176-6-114.san.res.rr.com",
- "78.182.186.76.dynamic.ttnet.com.tr",
- "spr57-1-78-222-164-204.fbx.proxad.net",
- "79-112-127-121.iasi.fiberlink.ro",
- "79-113-243-123.rdsnet.ro",
- "athedsl-374630.home.otenet.gr",
- "80.85.116.247",
- "97.80-203-109.nextgentel.com",
- "mas91-1-82-238-220-55.fbx.proxad.net",
- "205.84-49-113.nextgentel.com",
- "546AF74A.cm-12-3d.dynamic.ziggo.nl",
- "bzq-84-109-215-126.red.bezeqint.net",
- "84.126.53.114.dyn.user.ono.com",
- "85-89-31.11.3p.ntebredband.no",
- "ti0020a380-dhcp0769.bb.online.no",
- "85-220-20-210.dsl.dynamic.simnet.is",
- "bl7-28-21.dsl.telepac.pt",
- "bl10-62-182.dsl.telepac.pt",
- "bl13-32-50.dsl.telepac.pt",
- "cpc5-stok15-2-0-cust153.1-4.cable.virginmedia.com",
- "host86-163-166-134.range86-163.btcentralplus.com",
- "87.69.205.190",
- "89-72-74-184.dynamic.chello.pl",
- "ip-89-176-3-108.net.upcbroadband.cz",
- "ip-89-176-18-86.net.upcbroadband.cz",
- "bba791324.alshamil.net.ae",
- "cpc2-dals19-2-0-cust577.hari.cable.virginmedia.com",
- "95.57.54.75",
- "96.53.191.237",
- "pool-96-233-102-233.bstnma.fios.verizon.net",
- "109.64.214.62",
- "188-173-152-170.next-gen.ro",
- "59.95.14.193",
- "70-59-42-212.hlrn.qwest.net",
- "120.149.22.185",
- "177.159.11.228.dynamic.adsl.gvt.net.br",
- "178.192.46.219",
- "84.132.90.159",
- "c-89-233-207-234.cust.bredband2.com",
- "88.236.127.10.dynamic.ttnet.com.tr",
- "46-129-122-50.dynamic.upc.nl",
- "d154-20-26-194.bchsia.telus.net",
- "217.94.43.1",
- "189.51.155.66",
- "201.42.166.100",
- "72.131.95.33",
- "82.208.2.237",
- "77.74.36.17",
- "92.241.190.253",
- "212.204.176.126",
- "89.97.145.112",
- "modemcable006.144-179-173.mc.videotron.ca",
- "173.237.117.193",
- "174.48.115.21",
- "174.49.241.248",
- "174.57.227.136",
- "174.60.217.233",
- "CPE1859334715cf-CM1859334715cc.cpe.net.cable.rogers.com",
- "174.125.205.38",
- "175.136.107.218",
- "175.139.127.67",
- "175.213.202.225",
- "176.25.0.163",
- "176.27.20.129",
- "adsl-78.176.58.205.tellas.gr",
- "208.28.ftth.classcom.pl",
- "176.250.173.130",
- "176.253.139.206",
- "b0ff4da6.bb.sky.com",
- "176.255.92.226",
- "177.5.57.218",
- "177.18.54.151",
- "177.42.111.238",
- "177.96.149.234",
- "177.98.20.dynamic.adsl.gvt.net.br",
- "177.98.141.218",
- "178.36.43.60",
- "178.59.94.206",
- "178-85-44-28.dynamic.upc.nl",
- "178.128.93.32",
- "178.148.174.105",
- "178.148.184.65",
- "178.148.245.19",
- "28-208.194-178.cust.bluewin.ch",
- "178-221-3-255.dynamic.isp.telekom.rs",
- "179.236.104.135",
- "184.175.21.132",
- "109.247.127.146",
- "121.44.59.5",
- "121.217.76.41",
- "123.243.99.146",
- "124.148.177.48",
- "128.69.189.137",
- "130.234.176.202",
- "142.197.248.204",
- "173.246.4.225",
- "173.246.18.10",
- "174.24.98.4",
- "174.45.184.211",
- "174.54.169.160",
- "174.68.69.134",
- "174.118.28.249",
- "175.142.185.156",
- "175.143.133.205",
- "176.250.28.182",
- "177.134.66.4",
- "178.33.62.49",
- "178.128.183.34",
- "180.17.44.154",
- "180.200.179.92",
- "184.66.19.173",
- "184.96.169.181",
- "187.36.22.100",
- "187.241.220.134",
- "190.245.152.117",
- "197.162.62.43",
- "209.29.24.254",
- "213.57.192.154",
- "213.103.191.95",
- "216.118.133.17",
- "217.120.226.250",
- "47.64.159.147",
- "96.126.107.60",
- "184.106.55.74",
- "5.70.192.175",
- "177.18.180.185",
- "41.133.40.80",
- "111.186.108.77", // Shanghai uni
- "77.108.186.111",
- "186.137.248.206",
- "88.152.254.33"
- };
- std::vector<MX_Information> mxServers;
- unsigned int mxServersFound = 0,
- connectedSuccessfullyWithAuth = 0,
- connectedSuccessfullyWithoutAuth = 0;
- if(GetOwnMXServers(mxServers))
- printf("%40s ==> %s\n", "Oh look it is me", mxServers.at(0).name.c_str());
- for(int i = 0; i < _countof(address); i++)
- {
- mxServers.clear();
- if(!GetMXServers(address[i], mxServers))
- {
- continue;
- }
- mxServersFound++;
- printf("%40s ==> %s\n", address[i], mxServers.at(0).name.c_str());
- connectedSuccessfullyWithoutAuth += TestMxRecordConnectWithoutAuth(mxServers);
- connectedSuccessfullyWithAuth += TestMxRecordConnectWithAuth(mxServers);
- }
- printf("%i IPs\n"
- "%f had a MX\n"
- "%f could be connected to (with auth)\n"
- "%f could be connected to (without auth)\n",
- _countof(address),
- ((float)mxServersFound / (float)_countof(address)),
- ((float)connectedSuccessfullyWithAuth / (float)mxServersFound),
- ((float)connectedSuccessfullyWithoutAuth / (float)mxServersFound));
- }
- void TestSSLSocket()
- {
- SSLSocket s;
- const char* httpData = "GET / HTTP/1.0\r\n\r\n";
- char buf[1024] = {0};
- unsigned int len = _countof(buf) - 1;
- s.Connect("google.com", 443);
- s.Send(httpData);
- s.RecvLine(buf, len, _countof(buf)-1);
- printf("First line: %s\n", buf);
- len = _countof(buf) - 1;
- s.Recv(buf, len);
- printf("Rest: %s\n", buf);
- }
- void TestSocketTypeSwitch()
- {
- char buffer[256] = {0};
- size_t len = _countof(buffer) - 1;
- const char* httpData = "GET / HTTP/1.0\r\n\r\n";
- const char* server = "google.com";
- AbstractSocket* s = new NormalSocket();
- s->SetTimeout(SMTP_CONNECT_TIMEOUT);
- if(!s->Connect(server, 443))
- {
- printf("Cannot connect\n");
- return;
- }
- SOCKET orig_socket = s->GetSocket();
- delete s;
- SSLSocket* ssls = NULL;
- s = ssls = new SSLSocket();
- s->Disconnect(); // Free new created socket
- s->SetSocket(orig_socket);
- ssls->StartSSL(server);
- s->Send(httpData);
- s->Recv(buffer, len);
- printf("%s", buffer);
- }
- void TestSocket()
- {
- NormalSocket s;
- const char* httpData = "GET /flush.php HTTP/1.1\r\nHost: localhost\r\n\r\n";
- char buf[1024] = {0};
- unsigned int len = _countof(buf) - 1;
- s.Connect("localhost", 80);
- s.Send(httpData);
- s.RecvLine(buf, len, _countof(buf)-1);
- printf("First line: %s\n", buf);
- do
- {
- len = _countof(buf) - 1;
- s.Recv(buf, len);
- printf("%s", buf);
- }while(len);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement