How to run a Web server in Python to transfer files during a pentest

Transferring a file from a machine that does not have an FTP, SSH, or HTTP server installed can be a very challenging task. Fortunately for us, if the machine comes with Python, we can easily start a Web server using either the SimpleHTTPServer module for Python 2.x or the http.server module for Python 3.x.

To start a Web server, open a new terminal and go to the directory where you have the files or documents that you want to download.

cd Documents

Once you are there, type the following command.

python -m SimpleHTTPServer 8888

This command will instantly serve the current directory on port 8888. Now, we just need to get the IP address of this machine and simply connect to it using any browser.

/sbin/ifconfig

And there is, a simple and easy way to transfer files and documents from a remote machine using only Python (NOTE: To use Python3, replace SimpleHTTPServer with http.server)