• Lunes 18 de Noviembre de 2024, 17:30

Autor Tema:  Urgente  (Leído 1638 veces)

exjoe

  • Miembro activo
  • **
  • Mensajes: 25
    • Ver Perfil
Urgente
« en: Miércoles 7 de Marzo de 2007, 23:26 »
0
te explicare detallado
para conectarme a internet configuro cualquiera  de los navegadores con el ip del serviod y proxy 3128
y luego empiezo a navegar pero ya a partir de la 6:00 pm no puedo revisdar nigun correo email por la web en internet, incluso cuando trato de conectarme a este sitio e identificarme me sale un error de denegacion que no puedo revisar web email, igual,pasa cuando trato de descargar algun programa y me pide direccion de correo y contraseña... me han dicho que esto es por causa del firewall que ademas controla mi horarior de descargar, o sea que solo puedo descargar a partir de las 12:00 de la noche hasta las 6:00am, entonces que me dicen por cierto
si puueden envienme el http tunnel por correo que me hace falta para probarlo ya que muchos me dicen que funciana pero si crees o tienes algo mejor que esto espero me puedas ayudar.. gracias navego con internet explorer,6.0 mozilla firefox,ect
Que debo hacer para quitarme tantas restricciones

Bicholey

  • Moderador
  • ******
  • Mensajes: 1234
    • Ver Perfil
Re: Urgente
« Respuesta #1 en: Jueves 8 de Marzo de 2007, 00:51 »
0
:P  :P  :P

No tienes que abrir varios hilos para lo mismo continua la discucion en uno solo.
 :angry:

no creo que sea un spyware, mas bien cuando termina turno simplemente bloquean los puertos, porque no lo se quiza para evitar el espionaje corporativo, como salir hay varias formas una es la que dices httptunnel otra es cambiar el puerto mediante el cual navegas.
Citar
La solución que yo he encontrado es tener un servidor externo cuya misión es recibir peticiones web por el puerto 443 y reenviarlas a la dirección adecuada por el puerto 80. De ésta manera, desde el trabajo, realizo la petición de conexión segura por el puerto 443 a la dirección donde se encuentra el programa "pasarela". El proxy intenta realizar la conexíon segura con dicha IP, el programa pasarela lee entonces la cabecera HTTP y hace la petición al servidor adecuado por el puerto 80, que responde de vuelta a la pasarela, ésta confirma al proxy la conexión segura y reenvia los datos recogidos al proxy que, al estar bajo conexión segura, no filtra nada y entrega todo a mi PC en el puesto de trabajo.

El código fuente del programa pasarela lo coloco aquí:

Código: Text
  1.  
  2. //---------------------------------------------------------------------------
  3. #ifndef TunnelSocketsH
  4. #define TunnelSocketsH
  5. //---------------------------------------------------------------------------
  6. #include
  7. //---------------------------------------------------------------------------
  8. #define TNLSCK_WAIT_TIME 5000
  9. #define TNLSCK_RETRIES 6
  10. //---------------------------------------------------------------------------
  11. namespace NsHttpTunneling
  12. {
  13. enum TSocketType { stProxy, stSource, stTarget };
  14.  
  15. typedef void __fastcall (__closure *TNotifyLogEntry)(AnsiString);
  16.  
  17. //-----------------------------------------------------------------------
  18.  
  19. class TSocketLog : public TComponent
  20. {
  21. private:
  22. static AnsiString m_strLogFile;
  23. static int m_iInstances;
  24. static TStringList* m_slLog;
  25. static bool m_bLog;
  26. int m_iID;
  27.  
  28. TNotifyLogEntry m_OnAddLogEntry;
  29.  
  30. void __fastcall SetLog(bool bLog);
  31. protected:
  32. public:
  33. __fastcall TSocketLog(TComponent* Owner);
  34. __fastcall ~TSocketLog();
  35.  
  36. void __fastcall AddEntry(AnsiString strText);
  37. void __fastcall SaveLog();
  38.  
  39. __property AnsiString __fastcall LogFile = { read = m_strLogFile, write = m_strLogFile };
  40. __property bool __fastcall Logging = { read = m_bLog, write = SetLog };
  41. __property int __fastcall Instances = { read = m_iInstances };
  42. __property int __fastcall ID = { read = m_iID };
  43.  
  44. __property TNotifyLogEntry OnAddLogEntry = { read = m_OnAddLogEntry, write = m_OnAddLogEntry };
  45. };
  46. //-----------------------------------------------------------------------
  47. AnsiString TSocketLog::m_strLogFile = "";
  48. int TSocketLog::m_iInstances = 0;
  49. TStringList* TSocketLog::m_slLog = NULL;
  50. bool TSocketLog::m_bLog = true;
  51. //-----------------------------------------------------------------------
  52.  
  53. class TSocketPair : public TSocketLog
  54. {
  55. private:
  56. AnsiString m_strTargetHost;
  57. int m_iTargetPort;
  58. TClientSocket* m_clTargetSocket;
  59. TCustomWinSocket* m_cwSourceSocket;
  60. bool m_bSrcConnected;
  61. bool m_bTgtConnected;
  62. bool m_bBusy;
  63. bool m_bError;
  64.  
  65. TSocketNotifyEvent m_OnTargetConnected;
  66. TSocketNotifyEvent m_OnTargetRead;
  67. TSocketNotifyEvent m_OnSourceRead;
  68.  
  69. TCustomWinSocket* __fastcall GetTargetSocket();
  70.  
  71. void __fastcall SetTargetHost(AnsiString strHost);
  72. void __fastcall SetTargetPort(int iPort);
  73.  
  74. void __fastcall TargetConnected(TObject* Sender, TCustomWinSocket* Socket);
  75. void __fastcall OnReadData(TObject* Sender, TCustomWinSocket* Socket);
  76. void __fastcall OnDisconnect(TObject* Sender, TCustomWinSocket* Socket);
  77. void __fastcall SendToSource(TObject* Sender, TCustomWinSocket* Socket);
  78. void __fastcall SendToTarget(TObject* Sender, TCustomWinSocket* Socket);
  79.  
  80. void __fastcall SocketEventHandler(TObject* Sender, TCustomWinSocket* Socket, TSocketEvent SocketEvent);
  81. void __fastcall SocketErrorHandler(TObject* Sender, TCustomWinSocket* Socket, TErrorEvent ErrorEvent, int &ErrorCode);
  82. protected:
  83. __property TCustomWinSocket* __fastcall TargetSocket = { read = GetTargetSocket };
  84. __property TCustomWinSocket* __fastcall SourceSocket = { read = m_cwSourceSocket };
  85.  
  86. AnsiString __fastcall ParseHttpGetQuery(AnsiString strText, int& iPort);
  87. char* __fastcall ReadDataFromSocket(TCustomWinSocket* cwSocket, int& iLen);
  88. void __fastcall SendData(TCustomWinSocket* cwSocket, char* cBuffer, int iLen);
  89. public:
  90. __fastcall TSocketPair(TComponent* Owner, TCustomWinSocket* cwSourceSocket);
  91. __fastcall ~TSocketPair();
  92.  
  93. void __fastcall Open();
  94. void __fastcall Close();
  95.  
  96. __property AnsiString __fastcall TargetHost = { read = m_strTargetHost, write = SetTargetHost };
  97. __property int __fastcall TargetPort = { read = m_iTargetPort, write = SetTargetPort };
  98. __property bool __fastcall Busy = { read = m_bBusy };
  99. __property TSocketNotifyEvent OnTargetConnected = { read = m_OnTargetConnected, write = m_OnTargetConnected };
  100. __property TSocketNotifyEvent OnTargetRead = { read = m_OnTargetRead, write = m_OnTargetRead };
  101. __property TSocketNotifyEvent OnSourceRead = { read = m_OnSourceRead, write = m_OnSourceRead };
  102. };
  103. //-----------------------------------------------------------------------
  104.  
  105. class TSslBridge : public TSocketPair
  106. {
  107. private:
  108. char* m_cBuffer;
  109. int m_iLen;
  110.  
  111. void __fastcall SslTargetConnected(TObject* Sender, TCustomWinSocket* Socket);
  112. void __fastcall SslSourceRead(TObject* Sender, TCustomWinSocket* Socket);
  113. protected:
  114. public:
  115. __fastcall TSslBridge(TComponent* Owner, TCustomWinSocket* cwSourceSocket);
  116. __fastcall ~TSslBridge();
  117. };
  118. //-----------------------------------------------------------------------
  119.  
  120. class THttpTunnel : public TSocketPair
  121. {
  122. private:
  123. char* m_cBuffer;
  124. int m_iLen;
  125. AnsiString m_strBridgeHost;
  126. AnsiString m_strProxyHost;
  127. AnsiString m_strUser;
  128. AnsiString m_strPassword;
  129. int m_iProxyPort;
  130.  
  131. void __fastcall SetProxyHost(AnsiString strHost);
  132. void __fastcall SetProxyPort(int iPort);
  133.  
  134. AnsiString __fastcall IntToBase64(unsigned int uiNmb);
  135. AnsiString __fastcall Base64Encode(AnsiString strText);
  136.  
  137. void __fastcall TunnelTargetConnected(TObject* Sender, TCustomWinSocket* Socket);
  138. void __fastcall TunnelTargetRead(TObject* Sender, TCustomWinSocket* Socket);
  139. void __fastcall TunnelSourceRead(TObject* Sender, TCustomWinSocket* Socket);
  140. protected:
  141. public:
  142. __fastcall THttpTunnel(TComponent* Owner, TCustomWinSocket* cwSourceSocket);
  143. __fastcall ~THttpTunnel();
  144.  
  145. __property AnsiString __fastcall BridgeHost = { read = m_strBridgeHost, write = m_strBridgeHost };
  146. __property AnsiString __fastcall ProxyHost = { read = m_strProxyHost, write = SetProxyHost };
  147. __property int __fastcall ProxyPort = { read = m_iProxyPort, write = SetProxyPort };
  148. __property AnsiString __fastcall ProxyUser = { read = m_strUser, write = m_strUser };
  149. __property AnsiString __fastcall ProxyPswd = { read = m_strPassword, write = m_strPassword };
  150. };
  151. };
  152. //---------------------------------------------------------------------------
  153. #endif
  154.  
  155. Fuente 2
  156. Código:
  157.  
  158. //---------------------------------------------------------------------------
  159. #include
  160. #pragma hdrstop
  161.  
  162. #include "TunnelSockets.h"
  163. //---------------------------------------------------------------------------
  164. #pragma package(smart_init)
  165.  
  166. using namespace NsHttpTunneling;
  167.  
  168. __fastcall TSocketLog::TSocketLog(TComponent* Owner) : TComponent(Owner)
  169. {
  170. try
  171. {
  172. if(!m_iInstances)
  173. {
  174. m_strLogFile = Application->ExeName.SubString(1, Application->ExeName.Length() - ExtractFileExt(Application->ExeName).Length()) + ".log";
  175. m_slLog = new TStringList;
  176. }
  177. m_iID = ++m_iInstances;
  178. m_OnAddLogEntry = NULL;
  179. }
  180. catch(Exception& e)
  181. {
  182. MessageBox(Application->MainForm->Handle, e.Message.c_str(), "Error SocketLog", MB_OK | MB_ICONERROR | MB_APPLMODAL);
  183. }
  184. }
  185. //---------------------------------------------------------------------------
  186.  
  187. __fastcall TSocketLog::~TSocketLog()
  188. {
  189. try
  190. {
  191. --m_iInstances;
  192. if(!m_iInstances)
  193. {
  194. SaveLog();
  195. delete m_slLog;
  196. }
  197. }
  198. catch(Exception& e)
  199. {
  200. MessageBox(Application->MainForm->Handle, e.Message.c_str(), "Error SocketLog", MB_OK | MB_ICONERROR | MB_APPLMODAL);
  201. }
  202. }
  203. //---------------------------------------------------------------------------
  204.  
  205. void __fastcall TSocketLog::SetLog(bool bLog)
  206. {
  207. if(bLog != m_bLog && !bLog)
  208. SaveLog();
  209. m_bLog = bLog;
  210. }
  211. //---------------------------------------------------------------------------
  212.  
  213. void __fastcall TSocketLog::AddEntry(AnsiString strText)
  214. {
  215. if(m_bLog)
  216. {
  217. m_slLog->Add(FormatDateTime("dd-mmm-yy hh:nn:ss", Now()) + " [" + IntToStr(m_iID) + "]: " + strText);
  218. if(m_OnAddLogEntry)
  219. m_OnAddLogEntry(strText);
  220. }
  221. }
  222. //---------------------------------------------------------------------------
  223.  
  224. void __fastcall TSocketLog::SaveLog()
  225. {
  226. if(m_bLog && m_slLog->Count)
  227. m_slLog->SaveToFile(m_strLogFile);
  228. }
  229. //---------------------------------------------------------------------------
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236. __fastcall TSocketPair::TSocketPair(TComponent* Owner, TCustomWinSocket* cwSourceSocket) : TSocketLog(Owner)
  237. {
  238. try
  239. {
  240. m_strTargetHost = "";
  241. m_iTargetPort = -1;
  242. m_clTargetSocket = new TClientSocket(this);
  243. m_cwSourceSocket = cwSourceSocket;
  244. m_bBusy = false;
  245. m_bError = false;
  246. m_bSrcConnected = true;
  247. m_bTgtConnected = false;
  248. m_OnTargetConnected = NULL;
  249. m_OnTargetRead = NULL;
  250. m_OnSourceRead = NULL;
  251.  
  252. m_cwSourceSocket->OnSocketEvent = SocketEventHandler;
  253. m_cwSourceSocket->OnErrorEvent = SocketErrorHandler;
  254.  
  255. m_clTargetSocket->OnConnect = TargetConnected;
  256. m_clTargetSocket->Socket->OnSocketEvent = SocketEventHandler;
  257. m_clTargetSocket->Socket->OnErrorEvent = SocketErrorHandler;
  258. }
  259. catch(Exception& e)
  260. {
  261. AddEntry("TSocketPair constructor - " + e.Message);
  262. throw e;
  263. }
  264. }
  265. //---------------------------------------------------------------------------
  266.  
  267. __fastcall TSocketPair::~TSocketPair()
  268. {
  269. try
  270. {
  271. Close();
  272. delete m_clTargetSocket;
  273. }
  274. catch(Exception& e)
  275. {
  276. AddEntry("TSocketPair destructor - " + e.Message);
  277. throw e;
  278. }
  279. }
  280. //---------------------------------------------------------------------------
  281.  
  282. TCustomWinSocket* __fastcall TSocketPair::GetTargetSocket()
  283. {
  284. return m_clTargetSocket->Socket;
  285. }
  286. //---------------------------------------------------------------------------
  287.  
  288. void __fastcall TSocketPair::SetTargetHost(AnsiString strHost)
  289. {
  290. try
  291. {
  292. if(m_clTargetSocket->Socket->Connected)
  293. AddEntry("TSocketPair.SetTargetHost - TargetSocket already connected. Cannot change host");
  294. else
  295. m_strTargetHost = strHost;
  296. }
  297. catch(Exception& e)
  298. {
  299. AddEntry("TSocketPair.SetTargetHost - " + e.Message);
  300. throw e;
  301. }
  302. }
  303. //---------------------------------------------------------------------------
  304.  
  305. void __fastcall TSocketPair::SetTargetPort(int iPort)
  306. {
  307. try
  308. {
  309. if(iPort < 0 || iPort > 65535)
  310. throw Exception("Invalid port number " + IntToStr(iPort));
  311. else if(m_clTargetSocket->Socket->Connected)
  312. AddEntry("TSocketPair.SetTargetPort - TargetSocket already connected. Cannot change port");
  313. else
  314. m_iTargetPort = iPort;
  315. }
  316. catch(Exception& e)
  317. {
  318. AddEntry("TSocketPair.SetTargetPort - " + e.Message);
  319. throw e;
  320. }
  321. }
  322. //---------------------------------------------------------------------------
  323.  
  324. void __fastcall TSocketPair::TargetConnected(TObject* Sender, TCustomWinSocket* Socket)
  325. {
  326. try
  327. {
  328. if(Socket != m_clTargetSocket->Socket)
  329. return;
  330.  
  331. m_bTgtConnected = Socket->Connected;
  332.  
  333. if(m_OnTargetConnected)
  334. m_OnTargetConnected(Sender, Socket);
  335. }
  336. catch(Exception& e)
  337. {
  338. AddEntry("TSslBridge.TargetConnected - " + e.Message);
  339. throw e;
  340. }
  341. }
  342. //---------------------------------------------------------------------------
  343.  
  344. void __fastcall TSocketPair::OnReadData(TObject* Sender, TCustomWinSocket* Socket)
  345. {
  346. try
  347. {
  348. if(Socket == m_cwSourceSocket)
  349. {
  350. if(m_OnSourceRead)
  351. m_OnSourceRead(Sender, Socket);
  352. else
  353. SendToTarget(Sender, Socket);
  354. }
  355. else if(Socket == m_clTargetSocket->Socket)
  356. {
  357. if(m_OnTargetRead)
  358. m_OnTargetRead(Sender, Socket);
  359. else
  360. SendToSource(Sender, Socket);
  361. }
  362. }
  363. catch(Exception& e)
  364. {
  365. AddEntry("TSocketPair.OnReadData - " + e.Message);
  366. throw e;
  367. }
  368. }
  369. //---------------------------------------------------------------------------
  370.  
  371. void __fastcall TSocketPair::OnDisconnect(TObject* Sender, TCustomWinSocket* Socket)
  372. {
  373. try
  374. {
  375. if(Socket == m_cwSourceSocket && m_bTgtConnected)
  376. {
  377. AddEntry("Desconectado del socket destino");
  378. m_bTgtConnected = false;
  379. m_clTargetSocket->Close();
  380. }
  381. else if(Socket == m_clTargetSocket->Socket && m_bSrcConnected)
  382. {
  383. AddEntry("Desconectado del socket origen");
  384. m_bSrcConnected = false;
  385. m_cwSourceSocket->Close();
  386. }
  387. }
  388. catch(Exception& e)
  389. {
  390. AddEntry("TSocketPair.OnDisconnect - " + e.Message);
  391. throw e;
  392. }
  393. }
  394. //---------------------------------------------------------------------------
  395.  
  396. void __fastcall TSocketPair::SendToSource(TObject* Sender, TCustomWinSocket* Socket)
  397. {
  398. int i_len;
  399. char* c_buf = NULL;
  400. try
  401. {
  402. try
  403. {
  404. c_buf = ReadDataFromSocket(Socket, i_len);
  405. SendData(m_cwSourceSocket, c_buf, i_len);
  406. }
  407. catch(Exception& e)
  408. {
  409. AddEntry("TSocketPair.SendToTarget - " + e.Message);
  410. throw e;
  411. }
  412. }
  413. __finally
  414. {
  415. if(c_buf)
  416. delete[] c_buf;
  417. }
  418. }
  419. //---------------------------------------------------------------------------
  420.  
  421. void __fastcall TSocketPair::SendToTarget(TObject* Sender, TCustomWinSocket* Socket)
  422. {
  423. int i_len;
  424. char* c_buf = NULL;
  425. try
  426. {
  427. try
  428. {
  429. c_buf = ReadDataFromSocket(Socket, i_len);
  430. SendData(m_clTargetSocket->Socket, c_buf, i_len);
  431. }
  432. catch(Exception& e)
  433. {
  434. AddEntry("TSocketPair.SendToTarget - " + e.Message);
  435. throw e;
  436. }
  437. }
  438. __finally
  439. {
  440. if(c_buf)
  441. delete[] c_buf;
  442. }
  443. }
  444. //---------------------------------------------------------------------------
  445.  
  446. void __fastcall TSocketPair::SocketEventHandler(TObject* Sender, TCustomWinSocket* Socket, TSocketEvent SocketEvent)
  447. {
  448. try
  449. {
  450. switch(SocketEvent)
  451. {
  452. case seLookup:
  453. case seConnecting:
  454. case seListen:
  455. case seAccept:
  456. case seWrite:
  457. break;
  458. case seConnect:
  459. TargetConnected(Sender, Socket);
  460. break;
  461. case seDisconnect:
  462. OnDisconnect(Sender, Socket);
  463. break;
  464. case seRead:
  465. OnReadData(Sender, Socket);
  466. break;
  467. }
  468. }
  469. catch(Exception& e)
  470. {
  471. AddEntry("TSocketPair.SocketEventHandler - " + e.Message);
  472. throw e;
  473. }
  474. }
  475. //---------------------------------------------------------------------------
  476.  
  477. void __fastcall TSocketPair::SocketErrorHandler(TObject* Sender, TCustomWinSocket* Socket, TErrorEvent ErrorEvent, int &ErrorCode)
  478. {
  479. try
  480. {
  481. AddEntry(SysErrorMessage(ErrorCode));
  482. ErrorCode = 0;
  483. m_bError = true;
  484. Socket->Close();
  485. }
  486. catch(Exception& e)
  487. {
  488. AddEntry("TSocketPair.SocketErrorHandler - " + e.Message);
  489. }
  490. }
  491. //---------------------------------------------------------------------------
  492.  
  493. void __fastcall TSocketPair::SendData(TCustomWinSocket* cwSocket, char* cBuffer, int iLen)
  494. {
  495. try
  496. {
  497. #ifdef _DEBUG
  498. AnsiString str_add_entry = "";
  499. if(cwSocket == m_cwSourceSocket)
  500. str_add_entry = "TSocketPair.SendData - Target -> Source";
  501. else if(cwSocket == m_clTargetSocket->Socket)
  502. str_add_entry = "TSocketPair.SendData - Source -> Target";
  503. AddEntry(str_add_entry + " (" + IntToStr(iLen) + " bytes to send)");
  504. #endif
  505.  
  506. m_bBusy = true;
  507.  
  508. int i_retries = 0;
  509. int i_sent = cwSocket->SendBuf(cBuffer, iLen);
  510. #ifdef _DEBUG
  511. AddEntry(IntToStr(i_sent) + "/" + IntToStr(iLen) + " sent");
  512. #endif
  513. while(i_sent < iLen && i_retries < TNLSCK_RETRIES && !m_bError)
  514. {
  515. Sleep(TNLSCK_WAIT_TIME); // Espera TNLSCK_WAIT_TIME milisegundos antes de reintentarlo
  516. if(i_sent < 0) i_sent = 0;
  517. i_sent += cwSocket->SendBuf((cBuffer + i_sent), iLen - i_sent);
  518. ++i_retries;
  519. #ifdef _DEBUG
  520. AddEntry(IntToStr(i_sent) + "/" + IntToStr(iLen) + " sent");
  521. #endif
  522. }
  523.  
  524. m_bBusy = false;
  525.  
  526. if(m_bError)
  527. cwSocket->Close();
  528.  
  529. if(i_retries >= TNLSCK_RETRIES && i_sent < iLen)
  530. throw Exception("Could not send all data. " + IntToStr(i_sent * 100 / iLen) + "% completed");
  531. }
  532. catch(Exception& e)
  533. {
  534. AddEntry("TSocketPair.SendData - " + e.Message);
  535. throw e;
  536. }
  537. }
  538. //---------------------------------------------------------------------------
  539.  
  540. AnsiString __fastcall TSocketPair::ParseHttpGetQuery(AnsiString strText, int& iPort)
  541. {
  542. AnsiString str_host = "";
  543.  
  544. if(!strText.Pos("GET") && !strText.Pos("CONECT"))
  545. return AnsiString("");
  546.  
  547. try
  548. {
  549. int i_pos = strText.Pos("Host:");
  550.  
  551. str_host = strText.SubString(i_pos + 5, strText.Length()).Trim();
  552. if(str_host.Pos("r"))
  553. str_host = str_host.SubString(1, str_host.Pos("r") - 1).Trim();
  554. if(str_host.Pos("n"))
  555. str_host = str_host.SubString(1, str_host.Pos("n") - 1).Trim();
  556. if(str_host.Pos(":"))
  557. {
  558. iPort = StrToIntDef(str_host.SubString(str_host.Pos(":") + 1, str_host.Length()).Trim(), 80);
  559. str_host = str_host.SubString(1, str_host.Pos(":") - 1).Trim();
  560. }
  561.  
  562. if(iPort < 0 || iPort > 65535)
  563. AddEntry("TSslBridge.TargetConnect - Intento de conexión a puerto no válido " + IntToStr(iPort));
  564. else if(str_host.IsEmpty())
  565. AddEntry("TSslBridge.TargetConnect - Host no especificado para la conexión");
  566. }
  567. catch(Exception& e)
  568. {
  569. AddEntry("TSslBridge.TargetConnect - " + e.Message);
  570. throw e;
  571. }
  572. return str_host;
  573. }
  574. //---------------------------------------------------------------------------
  575.  
  576. char* __fastcall TSocketPair::ReadDataFromSocket(TCustomWinSocket* cwSocket, int& iLen)
  577. {
  578. char* c_buf = NULL;
  579. try
  580. {
  581. try
  582. {
  583. iLen = 3 * cwSocket->ReceiveLength() / 2;
  584. c_buf = new char[iLen];
  585. iLen = cwSocket->ReceiveBuf((void*)c_buf, iLen);
  586. }
  587. catch(Exception& e)
  588. {
  589. AddEntry("TSocketPair.ReadDataFromSocket - " + e.Message);
  590. throw e;
  591. }
  592. }
  593. __finally
  594. {
  595. return c_buf;
  596. }
  597. }
  598. //---------------------------------------------------------------------------
  599.  
  600. void __fastcall TSocketPair::Open()
  601. {
  602. try
  603. {
  604. if(!m_clTargetSocket->Socket->Connected)
  605. {
  606. m_clTargetSocket->Host = m_strTargetHost;
  607. m_clTargetSocket->Port = m_iTargetPort;
  608. m_clTargetSocket->Open();
  609. }
  610. }
  611. catch(Exception& e)
  612. {
  613. AddEntry("TSocketPair.Open - " + e.Message);
  614. throw e;
  615. }
  616. }
  617. //---------------------------------------------------------------------------
  618.  
  619. void __fastcall TSocketPair::Close()
  620. {
  621. try
  622. {
  623. if(m_clTargetSocket->Socket->Connected)
  624. m_clTargetSocket->Close();
  625. if(m_cwSourceSocket->Connected)
  626. m_cwSourceSocket->Close();
  627. }
  628. catch(Exception& e)
  629. {
  630. AddEntry("TSocketPair.Close - " + e.Message);
  631. throw e;
  632. }
  633. }
  634. //---------------------------------------------------------------------------
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641. __fastcall TSslBridge::TSslBridge(TComponent* Owner, TCustomWinSocket* cwSourceSocket) : TSocketPair(Owner, cwSourceSocket)
  642. {
  643. m_cBuffer = NULL;
  644. m_iLen = 0;
  645. OnTargetConnected = SslTargetConnected;
  646. OnSourceRead = SslSourceRead;
  647. }
  648. //---------------------------------------------------------------------------
  649.  
  650. __fastcall TSslBridge::~TSslBridge()
  651. {
  652. if(m_cBuffer)
  653. delete[] m_cBuffer;
  654. }
  655. //---------------------------------------------------------------------------
  656.  
  657. void __fastcall TSslBridge::SslTargetConnected(TObject* Sender, TCustomWinSocket* Socket)
  658. {
  659. try
  660. {
  661. try
  662. {
  663. //-- Send the target the request from the source
  664. SendData(Socket, m_cBuffer, m_iLen);
  665. }
  666. catch(Exception& e)
  667. {
  668. AddEntry("TSslBridge.SslTargetConnected - " + e.Message);
  669. throw e;
  670. }
  671. }
  672. __finally
  673. {
  674. if(m_cBuffer)
  675. delete[] m_cBuffer;
  676. m_cBuffer = NULL;
  677. m_iLen = 0;
  678. }
  679. }
  680. //---------------------------------------------------------------------------
  681.  
  682. void __fastcall TSslBridge::SslSourceRead(TObject* Sender, TCustomWinSocket* Socket)
  683. {
  684. try
  685. {
  686. int i_len;
  687. char* c_data = ReadDataFromSocket(Socket, i_len);
  688. AnsiString str_data = AnsiString(c_data);
  689. AnsiString str_host;
  690. int i_port = 80;
  691.  
  692. str_host = ParseHttpGetQuery(str_data, i_port);
  693. if(!str_host.IsEmpty())
  694. {
  695. #ifdef _DEBUG
  696. AddEntry("TSslBridge.SslSourceRead - Requesting: " + str_host + ":" +IntToStr(i_port));
  697. #endif
  698. TargetHost = str_host;
  699. TargetPort = i_port;
  700. m_cBuffer = c_data;
  701. m_iLen = i_len;
  702. OnSourceRead = NULL; // From now on we act as a bridge
  703.  
  704. Open(); // Finally, Open the target connexion
  705. }
  706. }
  707. catch(Exception& e)
  708. {
  709. AddEntry("TSslBridge.SslSourceRead - " + e.Message);
  710. throw e;
  711. }
  712. }
  713. //---------------------------------------------------------------------------
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721. __fastcall THttpTunnel::THttpTunnel(TComponent* Owner, TCustomWinSocket* cwSourceSocket) : TSocketPair(Owner, cwSourceSocket)
  722. {
  723. m_cBuffer = NULL;
  724. m_iLen = 0;
  725. m_strProxyHost = "";
  726. m_iProxyPort = 8080;
  727. OnTargetConnected = TunnelTargetConnected;
  728. OnTargetRead = TunnelTargetRead;
  729. OnSourceRead = TunnelSourceRead;
  730. }
  731. //---------------------------------------------------------------------------
  732.  
  733. __fastcall THttpTunnel::~THttpTunnel()
  734. {
  735. }
  736. //---------------------------------------------------------------------------
  737.  
  738. void __fastcall THttpTunnel::SetProxyHost(AnsiString strHost)
  739. {
  740. try
  741. {
  742. if(!TargetSocket->Connected)
  743. m_strProxyHost = strHost;
  744. }
  745. catch(Exception& e)
  746. {
  747. AddEntry("THttpTunnel.SetProxyHost - " + e.Message);
  748. throw e;
  749. }
  750. }
  751. //---------------------------------------------------------------------------
  752.  
  753. void __fastcall THttpTunnel::SetProxyPort(int iPort)
  754. {
  755. try
  756. {
  757. if(iPort < 0 || iPort > 65535)
  758. throw Exception("Puerto no válido: " + IntToStr(iPort));
  759. else if(!TargetSocket->Connected)
  760. m_iProxyPort = iPort;
  761. }
  762. catch(Exception& e)
  763. {
  764. AddEntry("THttpTunnel.SetProxyPort - " + e.Message);
  765. throw e;
  766. }
  767. }
  768. //---------------------------------------------------------------------------
  769.  
  770. AnsiString __fastcall THttpTunnel::IntToBase64(unsigned int uiNmb)
  771. {
  772. AnsiString str_rtn = "";
  773. try
  774. {
  775. try
  776. {
  777. if(uiNmb < 26)
  778. str_rtn = String(char(uiNmb + 'A'));
  779. else if(uiNmb < 52)
  780. str_rtn = String(char(uiNmb - 26 + 'a'));
  781. else if(uiNmb < 62)
  782. str_rtn = String(char(uiNmb - 52 + '0'));
  783. else if(uiNmb == 62)
  784. str_rtn = "+";
  785. else if(uiNmb == 63)
  786. str_rtn = "/";
  787. }
  788. catch(Exception& e)
  789. {
  790. AddEntry("THttpTunnel.IntToBase64 - " + e.Message);
  791. throw e;
  792. }
  793. }
  794. __finally
  795. {
  796. return str_rtn;
  797. }
  798. }
  799. //---------------------------------------------------------------------------
  800.  
  801. AnsiString __fastcall THttpTunnel::Base64Encode(AnsiString strText)
  802. {
  803. AnsiString str_rtn = "";
  804. try
  805. {
  806. try
  807. {
  808. unsigned int ui_len = strText.Length() / 3;
  809. unsigned int ui_mod = strText.Length() % 3;
  810. unsigned int ui_int_len = ui_len + (ui_mod ? 1 : 0);
  811. bool b_padding;
  812. char* c_text = new char[3 * ui_int_len + 1];
  813. unsigned int ui_6bit[4];
  814.  
  815. ZeroMemory(c_text, 3 * ui_int_len + 1);
  816. strcpy(c_text, strText.c_str());
  817.  
  818. for(unsigned int i = 0; i < ui_int_len; ++i)
  819. {
  820. ui_6bit[0] = (unsigned int)((c_text[3 * i] >> 2) & 0x0000003F);
  821. ui_6bit[1] = (unsigned int)(((c_text[3 * i] << 4) & 0x00000030) | ((c_text[3 * i + 1] >> 4) & 0x0000000F));
  822. ui_6bit[2] = (unsigned int)(((c_text[3 * i + 1] << 2) & 0x0000003C) | ((c_text[3 * i + 2] >> 6) & 0x00000003));
  823. ui_6bit[3] = (unsigned int)(c_text[3 * i + 2] & 0x0000003F);
  824.  
  825. if(i >= ui_len) // padding
  826. {
  827. str_rtn += IntToBase64(ui_6bit[0]);
  828. str_rtn += IntToBase64(ui_6bit[1]);
  829. if(!ui_mod)
  830. str_rtn += IntToBase64(ui_6bit[2]) + IntToBase64(ui_6bit[3]);
  831. else if(ui_mod == 1)
  832. str_rtn += "==";
  833. else if(ui_mod == 2)
  834. str_rtn += IntToBase64(ui_6bit[2]) + "=";
  835. }
  836. else
  837. {
  838. str_rtn += IntToBase64(ui_6bit[0]);
  839. str_rtn += IntToBase64(ui_6bit[1]);
  840. str_rtn += IntToBase64(ui_6bit[2]);
  841. str_rtn += IntToBase64(ui_6bit[3]);
  842. }
  843. }
  844.  
  845. delete[] c_text;
  846. }
  847. catch(Exception& e)
  848. {
  849. AddEntry("THttpTunnel.Base64Encode - " + e.Message);
  850. throw e;
  851. }
  852. }
  853. __finally
  854. {
  855. return str_rtn;
  856. }
  857. }
  858. //---------------------------------------------------------------------------
  859.  
  860. void __fastcall THttpTunnel::TunnelTargetConnected(TObject* Sender, TCustomWinSocket* Socket)
  861. {
  862. try
  863. {
  864. AnsiString str_auth = Base64Encode(m_strUser + ":" + m_strPassword);
  865. AnsiString str_data = "CONNECT " + m_strBridgeHost + ":443 HTTP/1.0n"
  866. + "Host: " + m_strBridgeHost + "n"
  867. + "Proxy-Authorization: Basic " + str_auth + "nn";
  868. //-- Pedimos conexión segura al proxy con el ordenador que está corriendo el
  869. // programa pasarela.
  870. SendData(Socket, str_data.c_str(), str_data.Length());
  871. }
  872. catch(Exception& e)
  873. {
  874. AddEntry("THttpTunnel.TunnelSourceRead - " + e.Message);
  875. throw e;
  876. }
  877. }
  878. //---------------------------------------------------------------------------
  879.  
  880. void __fastcall THttpTunnel::TunnelTargetRead(TObject* Sender, TCustomWinSocket* Socket)
  881. {
  882. int i_len;
  883. char* c_data;
  884. AnsiString str_data;
  885. try
  886. {
  887. try
  888. {
  889. c_data = ReadDataFromSocket(Socket, i_len);
  890. str_data = AnsiString(c_data);
  891.  
  892. OnTargetRead = NULL;
  893. if(str_data.Pos("HTTP/1.1 200 "))
  894. SendData(Socket, m_cBuffer, m_iLen);
  895. else
  896. AddEntry("THttpTunnel.TunnelTargetRead - Connexion not established");
  897. }
  898. catch(Exception& e)
  899. {
  900. AddEntry("THttpTunnel.TunnelTargetRead - " + e.Message);
  901. throw e;
  902. }
  903. }
  904. __finally
  905. {
  906. if(c_data)
  907. delete[] c_data;
  908. if(m_cBuffer)
  909. delete[] m_cBuffer;
  910. m_cBuffer = NULL;
  911. m_iLen = 0;
  912. }
  913. }
  914. //---------------------------------------------------------------------------
  915.  
  916. void __fastcall THttpTunnel::TunnelSourceRead(TObject* Sender, TCustomWinSocket* Socket)
  917. {
  918. try
  919. {
  920. m_cBuffer = ReadDataFromSocket(Socket, m_iLen);
  921. TargetHost = m_strProxyHost;
  922. TargetPort = m_iProxyPort;
  923. OnSourceRead = NULL; // From now on we act as a bridge
  924.  
  925. Open(); // Finally, Open the target connexion
  926. }
  927. catch(Exception& e)
  928. {
  929. AddEntry("THttpTunnel.TunnelSourceRead - " + e.Message);
  930. throw e;
  931. }
  932. }
  933. //---------------------------------------------------------------------------
  934.  
  935.  
  936.  
  937.  
[size=109]LOS GATOS SIEMPRE CAEMOS DE PIE !!![/size]


exjoe

  • Miembro activo
  • **
  • Mensajes: 25
    • Ver Perfil
Re: Urgente
« Respuesta #2 en: Jueves 8 de Marzo de 2007, 05:31 »
0
Si, pero esto es una unit.. como mando a llamar todas esas funciones y en que orden
ademas, si puedes me puedes enviar a cesar_ex_joe@yahoo.es el httptunnel compactado con otro nombre a ver si logro...

Bicholey

  • Moderador
  • ******
  • Mensajes: 1234
    • Ver Perfil
Re: Urgente
« Respuesta #3 en: Jueves 8 de Marzo de 2007, 17:56 »
0
:lol:  :lol:  :lol:  :lol:

No creo que nadie se tome la molestia de enviarte el httptunnel a tu mail, porque no te lo envias tu mismo desde tu casa.
[size=109]LOS GATOS SIEMPRE CAEMOS DE PIE !!![/size]