zinho writes: Before we see how server side works I must clarify the aim of this article cause it as misunderstood by some very
smart people. This tutorial (divided into 2 parts) is aimed to demonstrate to all VB beginners how VB can be used for hacking/advanced purposes.

After this little clarification we can go analyze the server side code that is much more interesting than
client. This time we have to:
1) recognize the command received
2) recognize the directory requested
3) open it and list its content
4) send the content to the client

To do the job I used Scripting.FileSystemObject that is a library that allows us to gain access over
windows filesystem (open dirs/files, create files...).

'**************************
dim fso=Scripting.FileSystemObject
set fso=new Scripting.FileSystemObject
***************************
Before you run the program remember to add the Scripting Runtime reference into the references box (Project->References).

'**************************
Private Sub Form1_Load()
ws.localport=6969
ws.listen
'**************************

'******************************************
Private Sub ws_DataArrival(ByVal bytesTotal As Long)
strCommand = ""
ws.GetData strCommand, vbString

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'DRIVES READY AND PRESENT
If Left(strCommand, 12) = "DRIVELISTING" Then

ws.SendData "DRIVELISTING" & CheckDrive

Exit Sub
End If
End Sub
'*******************************************
Wit these 2 snippets of code we open 6969 port and listen. When we receive a buffer we evaluate it and call CheckDrive function.
CheckDrive is a function that let us know which are the installed drives and which, among them, are ready:


'*********************************************
Public Function CheckDrive() As String
'2= Hdd 4=cdrom

Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
Dim driv
ReDim driv(5)

driv(0) = "c"
driv(1) = "d"
driv(2) = "e"
driv(3) = "f"
driv(4) = "g"
driv(5) = "h"
For Each l In driv
If fso.DriveExists(CStr(l)) = True Then
If fso.Drives(l).IsReady = True Then
res = res + l + ":" + "True"
res = res + ";"
End If
End If
Next
Set fso = Nothing
CheckDrive = res
End Function
'**************************************************
As we can see a list of drives is returned.

Now we get back to the Ws_DataArrival event and add this code that let the client navigate through the directories:

'************************************************
If Left(strCommand, 11) = "DIRLISTING:" Then
Dim strDir As String
strDir = Replace(strCommand, "DIRLISTING:", "")
If InStr(strDir, ":") = 0 Then 'If it is a drive letter
strDir = strDir + ":\"
End If
ws.SendData "DIRLISTING:" & GetFolderListing(strDir)
DoEvents
Exit Sub
End If
'*******************************************

Once again we use a function: this time to get the content of a folder:
'*******************************************
Public Function GetFolderListing(dir As String) As String

Dim myfolder As Folder

Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject

If Len(dir) = 1 Then 'it is a drive !
dir = dir & ":"
End If

If fso.FolderExists(dir) = True Then 'If the folder exists
Set myfolder = fso.GetFolder(dir)
Set filelist = myfolder.Files
Set dirlist = myfolder.SubFolders

For Each f In filelist 'FILE LISTING
ff = ff + f + ";"
Next

For Each d In dirlist 'DIR LISTING
dd = dd & d & ";"
Next

res = ff & "*" & dd 'IT SPLITS DIRS AND FILE WITH '*'
GetFolderListing = res
Else
Exit Function
End If

Set fso = Nothing
Set myfolder = Nothing

End Function
'**********************************************
As you can see, this is the most interesting part of our tutorial. In fact we get, very easily, a drive listing
by issuing proper well-known command.
Such a way we get our completely smooth remote drive navigator.

I wanna say thanks to everyone who have mailed me and to whom appreciated my work.


Download Tourniquet: http:\\[url]www.hackerscenter.com[/url]\zinhosoft\tourniquet
http:\\[url]www.hackerscenter.com[/url]
Zinho - [email][email protected][/email]