Guest User

Untitled

a guest
Jul 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. #include <File.au3>
  2. #include <Array.au3>
  3.  
  4. Global Const $nWelcomeMessage = "Telnet root thing v1" & @CRLF & "Type HELP to see a list of the available commands."
  5.  
  6. Dim $sBeta = True ; change this to false in release
  7.  
  8. Dim $sSocket[10], $sBuffer[10], $sPath[10]
  9. Dim $nRoot = @HomeDrive
  10.  
  11. For $x = 0 to UBound($sPath)-1
  12. $sPath[$x] = $nRoot
  13. Next
  14.  
  15. TCPStartup()
  16.  
  17. $sMainSocket = TCPListen(@IPAddress1,23,5)
  18.  
  19. While 1
  20. $sNewSocket = TCPAccept($sMainSocket)
  21. If $sNewSocket > -1 Then
  22. For $x = 0 to UBound($sSocket)-1
  23. If Not $sSocket[$x] Then
  24. $sSocket[$x] = $sNewSocket
  25. TCPSend($sSocket[$x],$nWelcomeMessage)
  26. TCPSend($sSocket[$x], @CRLF & @CRLF & $sPath[$x] & ">")
  27. ExitLoop
  28. EndIf
  29. Next
  30. EndIf
  31. For $x = 0 to UBound($sSocket)-1
  32. If $sSocket[$x] Then
  33. $sData = TCPRecv($sSocket[$x],100)
  34. $sBuffer[$x] &= $sData
  35. If @error Then
  36. TCPCloseSocket($sSocket[$x])
  37. $sSocket[$x] = ""
  38. If $sBeta Then Exit
  39. ElseIf Asc($sData) = 0x8 Then ;backspace received
  40. $len = StringLen($sBuffer[$x])
  41. $sBuffer[$x] = StringTrimRight($sBuffer[$x],2) ; trim the buffer
  42. If $len = 1 Then
  43. TCPSend($sSocket[$x],">")
  44. Else
  45. TCPSend($sSocket[$x]," " & Chr(0x8))
  46. EndIf
  47. EndIf
  48. If StringInStr($sBuffer[$x],@CRLF) Then
  49. $sCommand = StringTrimRight($sBuffer[$x],2)
  50. $sAnswer = ProcessCommand($sCommand)
  51. If @error = 1 Then
  52. TCPCloseSocket($sSocket[$x])
  53. $sSocket[$x] = ""
  54. If $sBeta Then Exit
  55. EndIf
  56. TCPSend($sSocket[$x],@CRLF & $sAnswer)
  57. TCPSend($sSocket[$x], @CRLF & $sPath[$x] & ">")
  58. $sBuffer[$x] = ""
  59. EndIf
  60. EndIf
  61. Next
  62. WEnd
  63.  
  64. Func ProcessCommand($fCommand)
  65. Local $fAnswer
  66.  
  67. $fParam = StringSplit($fCommand," ")
  68.  
  69. Switch $fParam[1]
  70. Case "HELP"
  71. $fAnswer = "Command" & @TAB & "Description" & @CRLF & _
  72. "HELP" & @TAB & "Lists all the available commands." & @CRLF & _
  73. "AYT" & @TAB & "Standard ""Are you there"" command."
  74. Case "AYT"
  75. $fAnswer = "I am here."
  76. Case "DIR"
  77. $fAnswer = "FILENAME TYPE" & @CRLF & @CRLF
  78. $fDir = _FileListToArray($sPath[$x],"*",2)
  79. $fFile = _FileListToArray($sPath[$x],"*",1)
  80. For $i = 0 to UBound($fDir)-1
  81. $len = StringLen($fDir[$i])
  82. For $j = 30 to $len Step -1
  83. $fDir[$i] &= " "
  84. Next
  85. Next
  86. For $i = 0 to UBound($fFile)-1
  87. $len = StringLen($fFile[$i])
  88. For $j = 30 to $len Step -1
  89. $fFile[$i] &= " "
  90. Next
  91. Next
  92. _ArrayDelete($fFile,0)
  93. _ArrayDelete($fDir,0)
  94. If UBound($fDir) <> 0 Then
  95. $fAnswer &= _ArrayToString($fDir,"<DIR>" & @CRLF) & "<DIR>" & @CRLF
  96. EndIf
  97. If UBound($fFile) <> 0 Then
  98. $fAnswer &= _ArrayToString($fFile,"<FILE>" & @CRLF) & "<FILE>" & @CRLF
  99. EndIf
  100. If $fAnswer = "FILENAME TYPE" & @CRLF & @CRLF Then
  101. $fAnswer = "FILENAME TYPE" & @CRLF & "No files or directories." & @CRLF
  102. EndIf
  103. Case "CD"
  104. If $fParam[0] > 1 Then
  105. Switch $fParam[2]
  106. Case ".."
  107. $sPath[$x] = StringLeft($sPath[$x], StringInStr($sPath[$x],"\",0,-1) -1)
  108. Case "\"
  109. $sPath[$x] = StringLeft($sPath[$x],2)
  110. Case Else
  111. $sSearch = FileFindFirstFile($sPath[$x] & "\" & $fParam[2])
  112. If $sSearch = -1 Then
  113. $fAnswer = "Cannot find file or directory."
  114. Else
  115. While 1
  116. $sFile = FileFindNextFile($sSearch)
  117. If @error Then
  118. $fAnswer = "Cannot find file or directory."
  119. ExitLoop
  120. EndIf
  121. If StringInStr(FileGetAttrib($sPath[$x] & "\" & $sFile),"D") Then
  122. $sPath[$x] &= "\" & $sFile
  123. ExitLoop
  124. EndIf
  125. WEnd
  126. EndIf
  127. EndSwitch
  128. EndIf
  129. Case "EXIT"
  130. Return SetError(1,0,1)
  131. Case Else
  132. If $fParam[1] <> "" Then
  133. ShellExecute($fParam[1], "", $sPath[$x])
  134. If @error Then
  135. $fAnswer = "'" & $fCommand & "' is not recognized as an internal or external command," & @CRLF & _
  136. "operable program or batch file."
  137. EndIf
  138. EndIf
  139. EndSwitch
  140.  
  141. Return $fAnswer
  142. EndFunc
Add Comment
Please, Sign In to add comment