bez zbędnych wstępów, jedziemy z tematem, ponieważ trochę mi to zajmie. (Specjalnie dla Was zainstalowałem Windowsa.
![Mr. Green :mrgreen:](./images/smilies/icon_mrgreen.gif)
![Obrazek](http://imagizer.imageshack.us/v2/455x261q90/673/Hlt5mc.png)
TigerTelentServ - bezpieczny demon
usługi Telnet dla
systemu Windows
Wykorzystujemy dwa pliki Form1.frm oraz Form2.frm.
Form1.frm zawiera kod podstawowego interfejsu demona. Obejmuje on analizator sesji,
opcję tymczasowego wyłączenia możliwości logowania oraz funkcję administracyjną
Lockdown. Wywołuje ona Form2.frm, który inicjalizuje specjalny demon, dopuszczający
jedną tylko sesję, przy której stosuje się hasło administratora - zapisane i skompilowane
wraz z kodem źródłowym. W tym trybie zalogować się można wyłącznie na konto - ad
ministrator.
Oto pierwszy formularz Form1.frm:
Kod: Zaznacz cały
Private Sub acc_ConnectionRequest(ByVal requestID As Long)
i = i + 1
Load pol(i)
pol(i).Close
pol(i).Accept requestID
acc.Close
acc.Listen
For scan = 1 To 35
If Ac_Name(scan) = Empty Then
refid = scan
Exit For
End If
Next scan
Ac_Name(refid) = "no user"
Ac_Host(refid) = pol(i).RemoteHostIP
Ac_What(refid) = "login"
Ac_Sock(refid) = i
SendFile "files\connect.txt", refid
Send Crt, refid
Send "Login: ", refid
Update
End Sub
Private Sub Command3_Click()
End Sub
Private Sub Command1_Click()
Unload Me
Form2.Show
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Update()
List1.Clear
For scan = 1 To 35
If Ac_Name(scan) <> Empty Then
If Ac_SuperUser(scan) = False Then
List1.AddItem Ac_Name(scan) & " - " & Ac_Host(scan)
Else
List1.AddItem "@" & Ac_Name(scan) & " - " & Ac_Host(scan)
End If
p = p + 1
End If
Next scan
Me.Caption = "Telnet - " & Trim(p) & " connection(s)"
End Sub
Private Sub Form_Load()
acc.LocalPort = 23
acc.Bind
acc.Listen
Crt = Chr(10) & Chr(13)
End Sub
Private Sub pol_Close(Index As Integer)
For scan = 1 To 3528
If Ac_Sock(scan) = Index Then
refid = scan
Exit For
End If
Next scan
Ac_Name(refid) = Empty
Ac_Input(refid) = Empty
Ac_Host(refid) = Empty
Ac_What(refid) = Empty
Ac_Sock(refid) = Empty
pol(Index).Close
Update
End Sub
Private Sub SendFile(ByVal filename As String, ByVal person As
Integer)
Open filename For Input As #1
Do
If EOF(1) Then Exit Do
Line Input #1, temp
Send temp & Chr(10) & Chr(13), person
Loop
Close #1
End Sub
Private Sub Send(ByVal text As String, ByVal person As Integer)
If Ac_Name(person) = "" Then Exit Sub
pol(Ac_Sock(person)).SendData text
End Sub
Private Sub pol_DataArrival(Index As Integer, ByVal bytesTotal As
Long)
pol(Index).GetData text, vbString
For scan = 1 To 35
If Ac_Sock(scan) = Index Then
refid = scan
Exit For
End If
Next scan
stack = ""
If refid = 0 Then
pol(Index).Close
Exit Sub
End If
For H = 1 To Len(text)
pg = Mid(text, H, 1)
If pg = Chr(13) Then
If Ac_What(refid) = "prompt" Then
reason = "command not found"
Ac_Input(refid) = Trim(Ac_Input(refid))
Send Crt, 1
If Ac_Input(refid) = Empty Then goodcom = True
For scan = 1 To Len(Ac_Input(refid))
If Mid(Ac_Input(refid), scan, 1) = " " Then
i_command = Mid(Ac_Input(refid), 1, scan - 1)
i_arg = Mid(Ac_Input(refid), scan + 1, 100)
Exit For
End If
Next scan
If i_command = "" Then i_command = Ac_Input(refid)
If i_command = "logout" Then
pol(Index).Close
Ac_Name(refid) = Empty
Ac_Input(refid) = Empty
Ac_Host(refid) = Empty
Ac_What(refid) = Empty
Ac_Sock(refid) = Empty
Ac_SuperUser(refid) = Empty
Update
Exit Sub
End If
If i_command = "shutdown" Then
If Ac_SuperUser(refid) = True Then
End
Else
goodcom = False
reason = "permission denied"
End If
End If
If i_command = "who" Then
goodcom = True
For scan = 1 To 35
If Ac_Name(scan) <> "" And Ac_Name(scan) <> "no
user" Then
result = ""
If Ac_SuperUser(scan) = True Then
result = "@"
End If
result = result & Ac_Name(scan)
For dscan = 1 To 10 - Len(result)
result = result & " "
Next dscan
result = result & Ac_Host(scan)
Send result & Crt, refid
End If
Next scan
End If
If i_command = "killuser" Then
If Ac_SuperUser(refid) = True Then
goodcom = False
reason = "no such user"
For scan = 1 To 35
If Ac_Name(scan) <> Empty Then
If Ac_Name(scan) = i_arg Then
pol(Ac_Sock(scan)).Close
Ac_Name(scan) = Empty
Ac_Input(scan) = Empty
Ac_Host(scan) = Empty
Ac_What(scan) = Empty
Ac_Sock(scan) = Empty
Ac_SuperUser(scan) = Empty
goodcom = True
Update
End If
End If
Next scan
Else
goodcom = False
reason = "permission denied"
End If
End If
If goodcom = False Then
stack = stack & "bash: " & i_command & ": " & reason
& Crt
End If
Ac_Input(refid) = Empty
stack = stack & Ac_Name(refid) & "@Telnet> "
Send stack, refid
Exit Sub
End If
If Ac_What(refid) = "login" Then
If Ac_Input(refid) = Empty Then
stack = stack & Crt
stack = stack & Crt
stack = stack & "Login: "
Send stack, refid
Exit Sub
End If
Ac_Name(refid) = Ac_Input(refid)
Ac_Input(refid) = Empty
stack = stack & Crt
stack = stack & "Password: "
Ac_What(refid) = "password"
Send stack, refid
Exit Sub
End If
If Ac_What(refid) = "password" Then
Open "files\users.ini" For Input As #1
Do
If EOF(1) Then Exit Do
Line Input #1, temp
If Mid(temp, 1, 1) <> "#" Then
G = 0
rscan:
For scan = 1 To Len(temp)
If Mid(temp, scan, 1) = "," Then
G = G + 1
If G = 1 Then
load_name = Mid(temp, 1, scan - 1)
temp = Mid(temp, scan + 1, 100)
GoTo rscan
End If
If G = 2 Then
load_password = Mid(temp, 1, scan -
1)
temp = Mid(temp, scan + 1, 100)
GoTo rscan
End If
If G = 3 Then
load_su = Mid(temp, 1, scan - 1)
temp = Mid(temp, scan + 1, 100)
End If
If Check1.Value = False Then
If load_name = Ac_Name(refid) Then
If load_password =
Ac_Input(refid) Then
stack = stack & Crt
stack = stack & "Login
approved." & Crt & Crt
stack = stack & Ac_Name(1) &
"@Telnet> "
Ac_What(refid) = "prompt"
Ac_Input(refid) = Empty
Ac_SuperUser(refid) = False
If load_su = "1" Then
Ac_SuperUser(refid) =
True
End If
Close #1
Send stack, refid
Update
Exit Sub
End If
Ac_Input(refid) = Empty
End If
End If
End If
Next scan
End If
Loop
Close #1
Ac_Input(refid) = Empty
stack = stack & Crt
stack = stack & "Login incorrect" & Crt & Crt
stack = stack & "Login: "
Send stack, refid
Ac_What(refid) = "Login"
Exit Sub
End If
End If
If pg = Chr(8) Then
If Ac_Input(refid) <> "" Then
Ac_Input(refid) = Mid(Ac_Input(refid), 1,
Len(Ac_Input(refid)) - 1)
If Ac_What(refid) <> "password" Then
Send Chr(8) & " " & Chr(8), refid
End If
End If
Exit Sub
End If
If pg = Chr(21) Then
If Ac_Input(refid) <> "" Then
For G = 1 To Len(Ac_Input(refid))
Send Chr(8) & " " & Chr(8), refid
Next G
End If
Ac_Input(refid) = ""
Exit Sub
End If
If Ac_What(refid) <> "password" Then
Send pg, refid
End If
Ac_Input(refid) = Ac_Input(refid) & pg
Next H
End Sub
Private Sub pol_Error(Index As Integer, ByVal Number As Integer,
Description As String, ByVal Scode As Long, ByVal Source As String,
ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As
Boolean)
For scan = 1 To 35
If Ac_Sock(scan) = Index Then
refid = scan
Exit For
End If
Next scan
Ac_Name(refid) = Empty
Ac_Input(refid) = Empty
Ac_Host(refid) = Empty
Ac_What(refid) = Empty
Ac_Sock(refid) = Empty
pol(Index).Close
Update
End Sub
rzystania przez administratora. Dopuszcza tylko jedną sesję, której zainicjowanie wy-
maga podania hasła zapisanego w kodzie źródłowym. Hasło to zapisane jest w wierszu:
Kod: Zaznacz cały
If Command =... Then... Else
![Mr. Green :mrgreen:](./images/smilies/icon_mrgreen.gif)
Form2.frm:
Kod: Zaznacz cały
Dim Pass As Boolean
Dim Command As String
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Form_Load()
Winsock1.LocalPort = 23
33
34
Hack Wars. Tom 2. Na tropie hakerów
Winsock1.Listen
Label1.Caption = ""
Dir1.Path = "C:\"
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
Do Until Winsock1.State = sckClosed
DoEvents
Loop
Winsock1.LocalPort = 23
Winsock1.Listen
Dir1.Path = "C:\"
Pass = False
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
Do Until Winsock1.State = 7
DoEvents
Loop
Me.Caption = Winsock1.RemoteHostIP
Winsock1.SendData "Password: "
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Data As String
Winsock1.GetData Data
If Asc(Data) = 13 Then
Label1.Caption = Command
If Pass = False Then
If Command = "steo" Then Pass = True: Winsock1.SendData
vbCrLf &
"welcome" & vbCrLf: Winsock1.SendData "C:\>" Else
Winsock1.SendData
"Password incorect!" & vbCrLf: Winsock1.SendData "Password: "
Else
If LCase(Command) = "cd.." Then
If Dir1.Path <> "C:\" Then Dir1.Path = ".."
If Dir1.Path <> "C:\" Then Winsock1.SendData
UCase(Dir1.Path) & "\>"
Else Winsock1.SendData "C:\>"
Command = ""
Exit Sub
End If
If LCase(Command) = "cd." Then
Dir1.Path = "."
If Dir1.Path <> "C:\" Then Winsock1.SendData
UCase(Dir1.Path) & "\>"
Else Winsock1.SendData "C:\>"
Command = ""
Exit Sub
End If
If LCase(Command) = "dir" Then
Dim Lenght As Integer
For i = 0 To Dir1.ListCount - 1
Winsock1.SendData Dir1.List(i) & "
<DIR>" & vbCrLf
Next
For i = O To File1.ListCount
Winsock1.SendData File1.List(i) & vbCrLf
34
Rozdział 1. ♦ Zabezpieczanie portów i usług
35
Next
If Dir1.Path <> "C:\" Then Winsock1.SendData
UCase(Dir1.Path) & "\>"
Else Winsock1.SendData "C:\>"
Command = ""
Exit Sub
End If
If LCase(Left(Command, 4)) = "view" Then
U = Right(Command, Len(Command) - 5)
On Error GoTo err1
If Dir1.Path = "C:\" Then
Open "C:\" & U For Input As #1
Do Until EOF(1)
Line Input #1, O
Winsock1.SendData O & vbCrLf
Loop
Close #1
Else
Open Dir1.Path & "\" & U For Input As #1
Do Until EOF(1)
Line Input #1, O
Winsock1.SendData O & vbCrLf
Loop
Close #1
End If
If Dir1.Path <> "C:\" Then Winsock1.SendData
UCase(Dir1.Path) & "\>"
Else Winsock1.SendData "C:\>"
Command = ""
Exit Sub
err1:
Winsock1.SendData Err.Description & vbCrLf
If Dir1.Path <> "C:\" Then Winsock1.SendData
UCase(Dir1.Path) & "\>"
Else Winsock1.SendData "C:\>"
Command = ""
Exit Sub
End If
If LCase(Left(Command, 2)) = "cd" And LCase(Left(Command, 3))
<> "cd." And
LCase(Left(Command, 3)) <> "cd\" And Len(Command) > 3 Then
U = Right(Command, Len(Command) - 3)
On Error GoTo err1
If Dir1.Path <> "C:\" Then Dir1.Path = Dir1.Path & "\" &
U Else
Dir1.Path = Dir1.Path & U
If Dir1.Path <> "C:\" Then Winsock1.SendData
UCase(Dir1.Path) & "\>"
Else Winsock1.SendData "C:\>"
Command = ""
Exit Sub
End If
If LCase(Command) = "cd\" Then
Dir1.Path = "C:\"
If Dir1.Path <> "C:\" Then Winsock1.SendData
UCase(Dir1.Path) & "\>"
Else Winsock1.SendData "C:\>"
Command = ""
Exit Sub
End If
If LCase(Command) = "quit" Then
35
36
Hack Wars. Tom 2. Na tropie hakerów
Winsock1.SendData "Goodbye!" & vbCrLf
Winsock1_Close
Command = ""
Exit Sub
End If
If LCase(Command) = "help" Then
Open App.Path & "\help.txt" For Input As #1
Do Until EOF(1)
Line Input #1, E
Winsock1.SendData E & vbCrLf
Loop
Close #1
If Dir1.Path <> "C:\" Then Winsock1.SendData
UCase(Dir1.Path) & "\>"
Else Winsock1.SendData "C:\>"
Command = ""
Exit Sub
End If
Winsock1.SendData "Wrong Command!" & vbCrLf & "Type help for
help" & vbCrLf
If Dir1.Path <> "C:\" Then Winsock1.SendData UCase(Dir1.Path)
& "\>" Else
Winsock1.SendData "C:\>"
End If
Command = ""
Else
Command = Command & Data
End If
End Sub
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)