EG Information

Main Index
EG Manual
Disclaimer
Legal Information
Hall of Fame
Hall of Shame
Member Rankings
Members List
Meet the Staff

Training Missions

Read Me First New
Basic Skills
Realistic Scenarios
Cryptography
Software Cracking
Linux ELF Binary Cracking
Logical Thinking
Programming
Patching
Steganography
Deface This Wall
/dev/null
/dev/urandom

Knowledge Bank

Discussion Forums
Enigma Chat New
RSS Feeds RSS
Articles / Tutorials
Videos
Online EG MP3 Player Radio
Enigma Zine
Downloads
Tools New

Code Resources

Submit Code
Ajax
ASM
Bash
C
CPP
Csharp
Delphi
Haskell
Java
Javascript
Jython
Lisp
mIRC
MySQL
Perl
PHP
Python
QBASIC
VisualBasic

Hakipedia: An open collaborative for all your information security needs.

The Urinal

Click Here To Vote For EG!

Has Enigma Group Helped You? Then Help Us By Advertising For Us. Place One Of The Following Images On Your Site.

enigma group

enigma group

enigma group

enigma group

Enigma Group's Code Bank


Linux Version C++ SOCKS 5 Proxy Server

By: BinaryShinigami  -  Date Submitted: 2009-04-17 13:29:42

  1. [DIR = ./]
  2. [FILE = ./main.cpp]
  3. #include <iostream>
  4. #include "socksHandler/sHandler.h"
  5. #include <vector>
  6.  
  7. //This version has been updated to work with *nix systems
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. cout << "Binary SOCKS5 Server V 0.1b" <<endl;
  14. cout <<"Currently only supports TCP connections with the Connect command." <<endl;
  15.  
  16. //WSAData wsaData;
  17. struct sockaddr_in server;
  18. int sockErr;
  19. int accSocket;
  20. unsigned short listenPort = 6666;
  21. fd_set constSet;
  22. fd_set retSet;
  23. timeval waitTime;
  24. int socksRdy;
  25. bool running = true;
  26. vector<sHandler*> users;
  27. int tmpSocket;
  28.  
  29. /*sockErr = WSAStartup(MAKEWORD(2,2),&wsaData);
  30. if (sockErr == SOCKET_ERROR)
  31. {
  32. cerr <<"ERROR : " <<WSAGetLastError();
  33. return -1;
  34. }*/
  35.  
  36.  
  37. accSocket = socket(AF_INET,SOCK_STREAM,0);
  38. if (accSocket == SOCKET_ERROR)
  39. {
  40. //cerr <<"ERROR: " <<WSAGetLastError();
  41. perror("ERROR");
  42. return -2;
  43. }
  44.  
  45. server.sin_family = AF_INET;
  46. server.sin_port = htons(listenPort);
  47. server.sin_addr.s_addr = INADDR_ANY;
  48.  
  49. sockErr = bind(accSocket,(sockaddr*)&server,sizeof(server));
  50. if (sockErr == SOCKET_ERROR)
  51. {
  52. //cerr <<"Error: Unable to bind Socket: " <<WSAGetLastError() <<endl;
  53. perror("bind");
  54. return -3;
  55. }
  56.  
  57. sockErr = listen(accSocket,10);
  58. if (sockErr == SOCKET_ERROR)
  59. {
  60. cerr <<"Unable to listen on socket: " <<errno <<endl;
  61. return -4;
  62. }
  63.  
  64. waitTime.tv_sec = 0;
  65. waitTime.tv_usec = 0;
  66.  
  67. FD_ZERO(&constSet);
  68. FD_ZERO(&retSet);
  69.  
  70. FD_SET(accSocket,&constSet);
  71. retSet = constSet;
  72.  
  73.  
  74. while(running)
  75. {
  76. retSet = constSet;
  77.  
  78. socksRdy = select(accSocket+1,&retSet,NULL,NULL,&waitTime);
  79. if (socksRdy == SOCKET_ERROR)
  80. {
  81. running = false;
  82. int er = errno;
  83. cerr <<"Unable to select() sockets: " <<er <<endl;
  84. //if (er == WSAEINTR)
  85. //{
  86. // cout <<"WSAEINTR" <<endl;
  87. //}
  88. cerr <<"socksRdy = " <<socksRdy <<endl;
  89. return -5;
  90. }
  91. if (socksRdy > 0)
  92. {
  93. cout <<"Accepted User" <<endl;
  94. tmpSocket = accept(accSocket,0,0);
  95. sHandler *usr = new sHandler(tmpSocket);
  96. users.push_back(usr);
  97. }
  98. for(int i = 0; i< users.size();i++)
  99. {
  100. if (users[i]->active)
  101. users[i]->m_HandleTransfers();
  102. else
  103. {
  104. sHandler *tmpHandler;
  105. vector<sHandler*>::iterator it;
  106. for (it = users.begin(); it < users.end(); it++)
  107. {
  108. if ((*it)->unique_id == users[i]->unique_id)
  109. {
  110. tmpHandler = users[i];
  111. users.erase(it);
  112. break;
  113. }
  114. }
  115. delete tmpHandler;
  116. }
  117. }
  118. }
  119.  
  120.  
  121. close(accSocket);
  122. //WSACleanup();
  123.  
  124. return 0;
  125. }
  126. [DIR = ./socksHandler/]
  127. [FILE = ./socksHandler/sAuthReply.cpp]
  128. #include "sAuthReply.h"
  129.  
  130. sAuthReply::sAuthReply()
  131. {
  132. this->m_cMethod = '';
  133. this->m_cVer = S_VER;
  134. }
  135.  
  136. sAuthReply::~sAuthReply()
  137. {
  138.  
  139. }
  140. [FILE = ./socksHandler/sAuthReply.h]
  141. #ifndef SAUTHREPLY_H_INCLUDED
  142. #define SAUTHREPLY_H_INCLUDED
  143.  
  144. #include "sProto.h"
  145.  
  146. class sAuthReply {
  147.  
  148. public:
  149. sAuthReply();
  150. ~sAuthReply();
  151.  
  152. char m_cVer;
  153. char m_cMethod;
  154.  
  155. };
  156.  
  157.  
  158. #endif // SAUTHREPLY_H_INCLUDED
  159. [FILE = ./socksHandler/sAuthRequest.cpp]
  160. #include "sAuthRequest.h"
  161.  
  162. sAuthRequest::sAuthRequest()
  163. {
  164. this->m_cNumMethods = '';
  165. this->m_cVer = S_VER;
  166. memset(this->m_szMethods,0,sizeof(this->m_szMethods));
  167. }
  168.  
  169. sAuthRequest::~sAuthRequest()
  170. {
  171.  
  172. }
  173. [FILE = ./socksHandler/sAuthRequest.h]
  174. #ifndef SAUTHREQUEST_H_INCLUDED
  175. #define SAUTHREQUEST_H_INCLUDED
  176.  
  177. #include "sProto.h"
  178. #include <cstring>
  179.  
  180. class sAuthRequest
  181. {
  182. public:
  183. sAuthRequest();
  184. ~sAuthRequest();
  185.  
  186. char m_cVer;
  187. char m_cNumMethods;
  188. char m_szMethods[256];
  189. };
  190.  
  191. #endif // SAUTHREQUEST_H_INCLUDED
  192. [FILE = ./socksHandler/sHandler.cpp]
  193. #include "sHandler.h"
  194.  
  195. unsigned int sHandler::g_id = 0;
  196.  
  197. sHandler::sHandler(int clientSocket)
  198. {
  199. this->isAuthed = false;
  200. this->isConnected = false;
  201. this->usrSocket = clientSocket;
  202. this->dstSocket = socket(AF_INET,SOCK_STREAM,0);
  203. memset(tmpBuffer,0,256);
  204. FD_ZERO(&this->allSocks);
  205. FD_ZERO(&this->rdySocks);
  206. authRequest = new sAuthRequest();
  207. authReply = new sAuthReply();
  208. request = new sRequest();
  209. reply = new sReply();
  210. this->active = true;
  211. unique_id = sHandler::g_id++;
  212. tmpSize = '';
  213. rdyCount = 0;
  214. waitTime.tv_sec = 0;
  215. waitTime.tv_usec = 0;
  216. memset(&locallyBoundInfo,0,sizeof(sockaddr));
  217.  
  218. cout <<this->unique_id <<" connected to server" <<endl;
  219. }
  220.  
  221. sHandler::~sHandler()
  222. {
  223.  
  224. if (this->dstSocket != 0)
  225. {
  226. close(this->dstSocket);
  227. }
  228.  
  229. close(this->usrSocket);
  230. delete authRequest;
  231. delete authReply;
  232. delete request;
  233. delete reply;
  234. cout <<this->unique_id <<" disconnected" <<endl;
  235.  
  236. }
  237.  
  238. void sHandler::m_HandleTransfers()
  239. {
  240. //This function is called in every one of the classes and allows us to transfer the data back and forth
  241. ;
  242. if (!this->isAuthed)
  243. {
  244. if (!this->m_Validate())
  245. {
  246. this->active = false;
  247. }
  248. }
  249. else
  250. {
  251. //Connected and Authorized now its time to connect to a server etc..
  252.  
  253. if (!this->m_HandleTunnel())
  254. {
  255. this->active = false;
  256. }
  257. }
  258.  
  259.  
  260.  
  261. }
  262.  
  263. //This function handles the authentication process, Currently this server does not support authentication
  264.  
  265. bool sHandler::m_Validate()
  266. {
  267. if (this->isAuthed)
  268. {
  269. return true;
  270. }
  271. else
  272. {
  273.  
  274. //Handle the initial authentication of the client here
  275.  
  276. m_BytesRead = recv(usrSocket,(char*)&authRequest->m_cVer,1,0);
  277.  
  278. if ((this->m_BytesRead < 1) || (this->m_BytesRead == SOCKET_ERROR))
  279. {
  280. //this->m_SockErr = WSAGetLastError();
  281. cerr <<" Reading Version Error: " << errno <<endl;
  282. cout <<"Recived: " <<authRequest->m_cVer <<endl;
  283. cout <<"Bytes Read: " <<m_BytesRead;
  284. return false;
  285. }
  286. else
  287. {
  288. m_BytesRead = recv(this->usrSocket,(char*)&authRequest->m_cNumMethods,1,0);
  289. if ((this->m_BytesRead < 1) || ( this->m_BytesRead > 1))
  290. {
  291. this->m_SockErr = errno;
  292. cerr <<"Reading numMethods Error: " <<this->m_SockErr <<endl;
  293. return false;
  294. }
  295.  
  296. m_BytesRead = recv(this->usrSocket,(char*)authRequest->m_szMethods,(int)authRequest->m_cNumMethods,0);
  297. cout <<"Recieved " <<m_BytesRead <<"Bytes, expecting " <<(int)authRequest->m_cNumMethods <<endl;
  298. cout <<authRequest->m_szMethods <<endl;
  299.  
  300.  
  301. if (this->authRequest->m_cVer != S_VER)
  302. {
  303. this->authReply->m_cMethod = S_NO_OK_METHOD;
  304. }
  305. else
  306. {
  307. this->authReply->m_cMethod = S_NO_AUTH_REQ;
  308. }
  309.  
  310. this->m_BytesRead = send(this->usrSocket,(char*)&this->authReply->m_cVer,1,0);
  311. if (this->m_BytesRead < 1)
  312. {
  313. this->m_SockErr = errno;
  314. cerr <<"Sending Version Error: " <<this->m_SockErr <<endl;
  315. }
  316. this->m_BytesRead = send(this->usrSocket,(char*)&this->authReply->m_cMethod,1,0);
  317. if (this->m_BytesRead < 1)
  318. {
  319. this->m_SockErr = errno;
  320. cerr <<"Sending Method Error: " <<this->m_SockErr <<endl;
  321. }
  322.  
  323. cout <<"Connected Successfully to client, waiting CONNECT." <<endl;
  324. //FINISHED AUTH
  325.  
  326.  
  327. this->isAuthed = true;
  328. return true;
  329. }
  330.  
  331. }
  332. }
  333.  
  334. void sHandler::m_HandleError()
  335. {
  336. perror("ERROR");
  337. }
  338.  
  339. //This function handles the data that will be passed between the usr and the target also it handles the CONNECT CMD
  340. bool sHandler::m_HandleTunnel()
  341. {
  342. if (!isConnected)
  343. {
  344. //Not connected so we have to handle the CONNECT CMD
  345. this->m_BytesRead = recv(this->usrSocket,(char*)&request->m_cVer,1,0);
  346. if ((m_BytesRead < 1) || (m_BytesRead == SOCKET_ERROR))
  347. {
  348. m_HandleError();
  349. return false;
  350. }
  351. if (request->m_cVer != S_VER)
  352. {
  353. cout <<"SOCKS VER: " <<request->m_cVer <<" : " <<(int)request->m_cVer <<endl;
  354. return false;
  355. }
  356.  
  357. this->m_BytesRead = recv(this->usrSocket,(char*)&request->m_cCmd,1,0);
  358. if ((m_BytesRead < 1) || (m_BytesRead == SOCKET_ERROR))
  359. {
  360. m_HandleError();
  361. return false;
  362. }
  363. cout <<"CMD: " <<(int)request->m_cCmd <<endl;
  364.  
  365. this->m_BytesRead = recv(this->usrSocket,(char*)&request->m_cReserved,1,0);
  366. if ((m_BytesRead < 1) || (m_BytesRead == SOCKET_ERROR))
  367. {
  368. m_HandleError();
  369. return false;
  370. }
  371.  
  372. this->m_BytesRead = recv(this->usrSocket, (char*)&request->m_cAddrType,1,0);
  373. if ((m_BytesRead < 1) || (m_BytesRead == SOCKET_ERROR))
  374. {
  375. m_HandleError();
  376. return false;
  377. }
  378. cout <<"ADDR TYPE: " <<request->m_cAddrType <<" : " <<(int)request->m_cAddrType <<endl;
  379.  
  380. switch(this->request->m_cAddrType)
  381. {
  382. case S_REQ_ADDR_IPV4:
  383. cout <<"Passed IPV4" <<endl;
  384. this->m_BytesRead = recv(this->usrSocket,(char*)&request->m_szDestAddr,S_REQ_IPV4_SIZE,0);
  385. if ((m_BytesRead < S_REQ_IPV4_SIZE) || (m_BytesRead == SOCKET_ERROR))
  386. {
  387. m_HandleError();
  388. return false;
  389. }
  390. hostentry = gethostbyname(request->m_szDestAddr);
  391. break;
  392. case S_REQ_ADDR_IPV6:
  393. cout <<"Passed IPV6 Address Type" <<endl;
  394. this->m_BytesRead = recv(this->usrSocket,(char*)&request->m_szDestAddr,S_REQ_IPV6_SIZE,0);
  395. if ((m_BytesRead < S_REQ_IPV6_SIZE) || (m_BytesRead == SOCKET_ERROR))
  396. {
  397. m_HandleError();
  398. return false;
  399. }
  400. hostentry = gethostbyname(request->m_szDestAddr);
  401. break;
  402. case S_REQ_ADDR_DOMAIN:
  403.  
  404. m_BytesRead = recv(this->usrSocket,(char*)&this->tmpSize,1,0);
  405. cout <<"tmpSize is " <<(int)this->tmpSize <<endl;
  406. if ((m_BytesRead < 1) || (m_BytesRead == SOCKET_ERROR))
  407. {
  408. m_HandleError();
  409. return false;
  410. }
  411. m_BytesRead = recv(this->usrSocket,(char*)request->m_szDestAddr,(int)tmpSize,0);
  412.  
  413. if ((m_BytesRead < (int)tmpSize) || (m_BytesRead == SOCKET_ERROR))
  414. {
  415. m_HandleError();
  416. return false;
  417. }
  418. hostentry = gethostbyname(request->m_szDestAddr);
  419. cout <<"request->m_szDestAddr = " <<request->m_szDestAddr <<endl;
  420. if (hostentry == NULL)
  421. {
  422. cout <<"Unable to find host" <<endl;
  423. return false;
  424. }
  425.  
  426. break;
  427. default:
  428. cout <<"Unknown ADDR_TYPE: " <<request->m_cAddrType <<" : " <<(int)request->m_cAddrType <<endl;
  429. return false;
  430. break;
  431. }
  432.  
  433.  
  434. m_BytesRead = recv(this->usrSocket,(char*)request->m_szDestPort,2,0);
  435. if ((m_BytesRead < 2) || (m_BytesRead == SOCKET_ERROR))
  436. {
  437. m_HandleError();
  438. return false;
  439. }
  440.  
  441. //Recived all the data needed to make the Connection
  442.  
  443. switch(request->m_cCmd)
  444. {
  445. case S_REQ_CONNECT:
  446. cout <<"Connection request generated!" <<endl;
  447. dstServer.sin_family = AF_INET;
  448. dstServer.sin_addr.s_addr = *(unsigned long*)hostentry->h_addr;
  449. dstServer.sin_port = (*(unsigned short*)&request->m_szDestPort[0]);
  450.  
  451. this->m_SockErr = connect(this->dstSocket,(sockaddr*)&dstServer,sizeof(dstServer));
  452. if (this->m_SockErr == SOCKET_ERROR)
  453. {
  454. m_HandleError();
  455. return false;
  456. }
  457. reply->m_cVer = S_VER;
  458. reply->m_cReply = S_REPLY_OK;
  459. reply->m_cReserved = S_RSV;
  460. reply->m_cAddrType = S_REPLY_ADDR_IPV4;
  461.  
  462. localSize = sizeof(locallyBoundInfo);
  463. if (getsockname(dstSocket,&locallyBoundInfo,(socklen_t*)&localSize))
  464. {
  465. cout <<"can't get locally bound info" <<endl;
  466. }
  467. cout <<"SA DATA " <<(int)locallyBoundInfo.sa_data <<endl;
  468. memcpy(reply->m_szBindAddr,&locallyBoundInfo.sa_data+2,4);
  469. memcpy(reply->m_szBindPort,&locallyBoundInfo.sa_data,2);
  470.  
  471. this->m_BytesRead = send(usrSocket,(char*)&reply->m_cVer,1,0);
  472. if (this->m_BytesRead > 1)
  473. {
  474. cout <<"More bytes than expected sent!" <<endl;
  475. }
  476. this->m_BytesRead = send(usrSocket,(char*)&reply->m_cReply,1,0);
  477. if (this->m_BytesRead > 1)
  478. {
  479. cout <<"More bytes than expected sent!" <<endl;
  480. }
  481. this->m_BytesRead = send(usrSocket,(char*)&reply->m_cReserved,1,0);
  482. if (this->m_BytesRead > 1)
  483. {
  484. cout <<"More bytes than expected sent!" <<endl;
  485. }
  486. this->m_BytesRead = send(usrSocket,(char*)&reply->m_cAddrType,1,0);
  487. if (this->m_BytesRead > 1)
  488. {
  489. cout <<"More bytes than expected sent!" <<endl;
  490. }
  491. this->m_BytesRead = send(usrSocket,(char*)&reply->m_szBindAddr,4,0);
  492. cout <<"BIND: " <<reply->m_szBindAddr <<endl;
  493. if (this->m_BytesRead > 4)
  494. {
  495. cout <<"More bytes than expected sent!" <<endl;
  496. }
  497. this->m_BytesRead = send(usrSocket,(char*)&reply->m_szBindPort,2,0);
  498. if (this->m_BytesRead > 2)
  499. {
  500. cout <<"More bytes than expected sent!" <<endl;
  501. }
  502. cout <<"Connected!" <<endl;
  503. cout <<"Tmp size is " <<(int)tmpSize <<endl;
  504. this->isConnected = true;
  505. FD_SET(dstSocket,&allSocks);
  506. FD_SET(usrSocket,&allSocks);
  507. //cout <<"All Socks set to " <<allSocks.fd_count <<endl;
  508. return true;
  509.  
  510. break;
  511. case S_REQ_ADDR_DOMAIN:
  512. cout <<"Domain Request Generated" <<endl;
  513. break;
  514. case S_REQ_BIND:
  515. cout <<"Bind Request Generated" <<endl;
  516. break;
  517. default:
  518. cout <<"Not yet handled Request" <<endl;
  519. return false;
  520. break;
  521.  
  522.  
  523. }
  524.  
  525.  
  526.  
  527. }
  528. else
  529. {
  530. //Relay Data between the sockets here
  531. rdySocks = allSocks;
  532. rdyCount = select(max(usrSocket,dstSocket)+1,&rdySocks,NULL,NULL,&waitTime);
  533. if (rdyCount == SOCKET_ERROR)
  534. {
  535. m_HandleError();
  536. cout <<"Select()" <<endl;
  537. return false;
  538. }
  539. //cout <<rdyCount <<" sockets Ready" <<endl;
  540. if (rdyCount > 0)
  541. {
  542.  
  543. //cout <<"reading from " <<i <<endl;
  544. if (FD_ISSET(usrSocket,&rdySocks))
  545. {
  546. //cout <<"Reading from usrSocket" <<endl;
  547. this->m_SockErr = recv(usrSocket,this->tmpBuffer,256,0);
  548. if (this->m_SockErr == SOCKET_ERROR)
  549. {
  550. /*
  551. if (WSAGetLastError() == WSAECONNRESET)
  552. {
  553. cout <<"Connection closed becuase WSACONNRESET" <<endl;
  554. this->active = false;
  555. }
  556. else{
  557. m_HandleError();
  558. cout <<"recv[" <<i <<"]" <<endl;
  559. }
  560. */
  561. m_HandleError();
  562. }
  563. if (this->m_SockErr == 0)
  564. {
  565. cout <<"Connection Closed BECUASE 0" <<endl;
  566. this->active = false;
  567. }
  568.  
  569. this->m_SockErr = send(dstSocket,this->tmpBuffer,m_SockErr,0);
  570. //cout <<"Sent to dstSocket" <<endl;
  571.  
  572.  
  573. memset(this->tmpBuffer,0,256);
  574. }
  575. if (FD_ISSET(dstSocket,&rdySocks))
  576. {
  577. //cout <<"Reading from destination" <<endl;
  578. this->m_SockErr = recv(dstSocket,this->tmpBuffer,256,0);
  579. if (this->m_SockErr == SOCKET_ERROR)
  580. {
  581. /*
  582. if (WSAGetLastError() == WSAECONNRESET)
  583. {
  584. cout <<"Connection closed becuase WSACONNRESET" <<endl;
  585. this->active = false;
  586. }
  587. else{
  588. m_HandleError();
  589. cout <<"recv[" <<i <<"]" <<endl;
  590. }
  591. */
  592. m_HandleError();
  593. }
  594. if (this->m_SockErr == 0)
  595. {
  596. cout <<"Connection Closed BECUASE 0" <<endl;
  597. this->active = false;
  598. }
  599.  
  600.  
  601. this->m_SockErr = send(usrSocket,this->tmpBuffer,m_SockErr,0);
  602. // cout <<"Sent to usrSocket" <<endl;
  603.  
  604.  
  605. memset(this->tmpBuffer,0,256);
  606. }
  607.  
  608. }
  609.  
  610. return true;
  611. }
  612.  
  613. }
  614. [FILE = ./socksHandler/sHandler.h]
  615. #ifndef SHANDLER_H_INCLUDED
  616. #define SHANDLER_H_INCLUDED
  617.  
  618. #include "sProto.h"
  619. #include "sAuthReply.h"
  620. #include "sAuthRequest.h"
  621. #include "sReply.h"
  622. #include "sRequest.h"
  623. #include <sys/select.h>
  624. #include <sys/time.h>
  625. #include <unistd.h>
  626.  
  627. #include <iostream>
  628.  
  629. /* This class handles the SOCKS5 Protocol for an individual tunnel and controls what has happened etc.*/
  630.  
  631. using namespace std;
  632.  
  633. class sHandler {
  634.  
  635. public:
  636. sHandler(int clientSocket);
  637. ~sHandler();
  638.  
  639. void m_HandleTransfers();
  640. bool active;
  641. static unsigned int g_id;
  642. unsigned int unique_id;
  643.  
  644.  
  645.  
  646. private:
  647. bool isConnected; //This will be used to tell if the connection was successful
  648. int usrSocket; //The socket that initially requests the connection
  649. int dstSocket; //The socket that will be used to make the connection
  650. fd_set allSocks;
  651. fd_set rdySocks;
  652. struct timeval waitTime;
  653. sRequest *request;
  654. sReply *reply;
  655. sAuthRequest *authRequest;
  656. sAuthReply *authReply;
  657. int m_SockErr;
  658. int m_BytesRead;
  659. bool isAuthed;
  660. bool m_HandleTunnel();
  661. bool m_Validate();
  662. void m_HandleError();
  663. struct hostent *hostentry;
  664. struct sockaddr_in dstServer;
  665. char tmpSize;
  666. char tmpBuffer[256];
  667. int rdyCount;
  668. struct sockaddr locallyBoundInfo;
  669. int localSize;
  670.  
  671. };
  672.  
  673. #endif // SHANDLER_H_INCLUDED
  674. [FILE = ./socksHandler/sProto.h]
  675. #ifndef SPROTO_H_INCLUDED
  676. #define SPROTO_H_INCLUDED
  677.  
  678. //This file contains all of the SOCKS5 Protocol constants and will be included in just about every file.
  679. //This is the SOCKS version and will always be 5 for a SOCKS5 server
  680. #define S_VER 5
  681.  
  682. //These are the possible SOCKS 5 Server authentication methods
  683. //This server will always use no auth but just for possible future expansion I'm including all the possible auth. methods
  684. #define S_NO_AUTH_REQ 0
  685. #define S_GSSAPI 1
  686. #define S_USERPASS 2
  687. #define S_IANA_ASS_BEG 3
  688. #define S_IANA_ASS_END 127
  689. #define S_PRIVATE_BEG 128
  690. #define S_PRIVATE_END 254
  691. #define S_NO_OK_METHOD 255
  692.  
  693. //These are the Request constants
  694. #define S_REQ_CONNECT 1
  695. #define S_REQ_BIND 2
  696. #define S_REQ_UDP_ASSOC 3
  697.  
  698. #define S_REQ_ADDR_IPV4 1
  699. #define S_REQ_ADDR_IPV6 4
  700. #define S_REQ_ADDR_DOMAIN 3
  701.  
  702. #define S_REQ_IPV4_SIZE 4
  703. #define S_REQ_IPV6_SIZE 16
  704.  
  705. //No define for domain b/c the 1st octect indicates the size of the domain that immediately follows, no terminating null
  706.  
  707. //RESERVED WILL ALWAYS BE x00 So we define it
  708. #define S_RSV 0
  709. //These are the Reply constants that are used
  710. #define S_REPLY_OK 0
  711. #define S_REPLY_GENERAL_FAIL 1
  712. #define S_REPLY_NOT_ALLOWED 2
  713. #define S_REPLY_NET_UNREACHABLE 3
  714. #define S_REPLY_HOST_UNREACHABLE 4
  715. #define S_REPLY_CONN_REFUSED 5
  716. #define S_REPLY_TTL_EXP 6
  717. #define S_REPLY_CMD_NOT_SUPPORTED 7
  718. #define S_REPLY_ADDR_NOT_SUPPORTED 8
  719.  
  720. #define S_REPLY_ADDR_IPV4 1
  721. #define S_REPLY_ADDR_IPV6 4
  722. #define S_REPLY_ADDR_DOMAIN 3
  723.  
  724. //We add the includes that all of the other crap will use since this file is included by all others
  725. #include <netdb.h>
  726. #include <sys/types.h>
  727. #include <sys/socket.h>
  728. #include <arpa/inet.h>
  729. #include <cstdio>
  730. #include <errno.h>
  731. #include <sys/select.h>
  732. #include <sys/time.h>
  733. #include <unistd.h>
  734.  
  735. #define SOCKET_ERROR -1
  736.  
  737.  
  738. #endif // SPROTO_H_INCLUDED
  739. [FILE = ./socksHandler/sReply.cpp]
  740. #include "sReply.h"
  741.  
  742. sReply::sReply()
  743. {
  744. this->m_cAddrType = '';
  745. this->m_cReply = '';
  746. this->m_cReserved = S_RSV;
  747. this->m_cVer = S_VER;
  748. memset(this->m_szBindAddr,0,sizeof(this->m_szBindAddr));
  749. memset(this->m_szBindPort,0,sizeof(this->m_szBindPort));
  750.  
  751. }
  752.  
  753. sReply::~sReply()
  754. {
  755.  
  756. }
  757. [FILE = ./socksHandler/sReply.h]
  758. #ifndef SREPLY_H_INCLUDED
  759. #define SREPLY_H_INCLUDED
  760.  
  761. #include "sProto.h"
  762. #include <cstring>
  763.  
  764. class sReply
  765. {
  766. public:
  767. sReply();
  768. ~sReply();
  769.  
  770. char m_cVer;
  771. char m_cReply;
  772. char m_cReserved;
  773. char m_cAddrType;
  774. char m_szBindAddr[256];
  775. char m_szBindPort[2];
  776.  
  777.  
  778. };
  779.  
  780.  
  781. #endif // SREPLY_H_INCLUDED
  782. [FILE = ./socksHandler/sRequest.cpp]
  783. #include "sRequest.h"
  784.  
  785. sRequest::sRequest()
  786. {
  787. this->m_cAddrType = '';
  788. this->m_cCmd = '';
  789. this->m_cReserved = S_RSV;
  790. this->m_cVer = S_VER;
  791. memset(this->m_szDestAddr,0,256);
  792. memset(this->m_szDestPort,0,2);
  793. }
  794.  
  795. sRequest::~sRequest()
  796. {
  797.  
  798. }
  799. [FILE = ./socksHandler/sRequest.h]
  800. #ifndef SREQUEST_H_INCLUDED
  801. #define SREQUEST_H_INCLUDED
  802.  
  803. #include "sProto.h"
  804. #include <cstring>
  805.  
  806. class sRequest {
  807.  
  808. public:
  809. sRequest();
  810. ~sRequest();
  811.  
  812. char m_cVer;
  813. char m_cCmd;
  814. char m_cReserved;
  815. char m_cAddrType;
  816. char m_szDestAddr[256];
  817. char m_szDestPort[2];
  818. };
  819.  
  820.  
  821. #endif // SREQUEST_H_INCLUDED
  822.  
Return to cpp category list

Who's Online

484 Guests, 101 Users
ckryptix, Ios, viper0i0, Diznablo, rabbidmind, asapong, Nasrudin, CollapsingWalls, mehtaparag, bitstrike, jnony, C, Nicid1, Nusquam-Redono-Sapientia, bazcrown, saifulfaizan, The End, Ultraminor, psychomarine, st3alth, themastersinner, pgmrlink, login, lionaneesh, ishkur88, mahraja, Mac, chekifr, gandalf88, Vap0r, t0ast, tantrum6226, BnE, Distorted, Psiber_Syn, Ausome1, invas10n, oldgoat, freedaysbecumei, BinaryShinigami, Rex_Mundi, Red_beard, Strobeflux, s0m3nak3dguy, Descent, teehee, machupicchu, Genetix, Anandarl, NotMyOwn, thegamerdude, Godzila, popo12341234, RedEvolution, velocity_b, myne17, teto111, aVoid, Central-Gsm, 1101, JackalReborn, InjectioN, h4lted, c0re, DisPater, markt4death, splatta, Jackowacko, saint556, Pyron2312, Azerion, howsens, white.hat.gone.bad, vazzilly, pwunkz, Inverted, QuarterCask, Infernoe11, deskata, cr4ck3rj4ck, Blizer, jasonmax, j0sh, gwenwavor, N4g4c3N, spizeyboy, Network X, Uino59, Jae Cee, ianFDK, saykov, medhaavee, zofy, demonkiller410, Stumble, SaMTHG, kishore, Raze, helasraizam, Venom1019, Jakabo