Pentesting Cheatsheets

Convenient commands for your pentesting / red-teaming engagements, OSCP and CTFs.

Reconnaissance / Enumeration

Extracting Live IPs from Nmap Scan

nmap 10.1.1.1 --open -oG scan-results; cat scan-results | grep "/open" | cut -d " " -f 2 > exposed-services-ips

Simple Port Knocking

for x in 7000 8000 9000; do nmap -Pn –host_timeout 201 –max-retries 0 -p $x 1.1.1.1; done

DNS lookups, Zone Transfers & Brute-Force

whois domain.com
dig {a|txt|ns|mx} domain.com
dig {a|txt|ns|mx} domain.com @ns1.domain.com
host -t {a|txt|ns|mx} megacorpone.com
host -a megacorpone.com
host -l megacorpone.com ns1.megacorpone.com
dnsrecon -d megacorpone.com -t axfr @ns2.megacorpone.com
dnsenum domain.com
nslookup -> set type=any -> ls -d domain.com
for sub in $(cat subdomains.txt);do host $sub.domain.com|grep "has.address";done

NFS Exported Shares

List NFS exported shares:

...and check if 'rw,no_root_squash' is present. If it is present, compile the below sid-shell.c:

...upload it to the share and execute the below to launch sid-shell to spawn a root shell:

Kerberos Enumeration

HTTP Brute-Force & Vulnerability Scanning

RPC / NetBios / SMB

SNMP

SMTP

Active Directory

Listen on a port (Powershell)

Gaining Access

Reverse Shell One-Liners

Bash

Perl

URL-Encoded Perl: Linux

Python

PHP

Ruby

Netcat without -e #1

Netcat without -e #2

Java

XTerm

JDWP RCE

Working with Restricted Shells

Interactive TTY Shells

Uploading/POSTing Files Through WWW Upload Forms

PUTing File on the Webhost via PUT verb

Generating Payload Pattern & Calculating Offset

Bypassing File Upload Restrictions

  • file.php -> file.jpg

  • file.php -> file.php.jpg

  • file.asp -> file.asp;.jpg

  • file.gif (contains php code, but starts with string GIF/GIF98)

  • 00%

  • file.jpg with php backdoor in exif (see below)

  • .jpg -> proxy intercept -> rename to .php

Injecting PHP into JPEG

Uploading .htaccess to interpret .blah as .php

Cracking Passwords

Cracking Web Forms with Hydra

Cracking Common Protocols with Hydra

HashCat Cracking

Generating Payload with msfvenom

Compiling Code From Linux

Compiling Assembly from Windows

Local File Inclusion to Shell

Local File Inclusion: Reading Files

Remote File Inclusion Shell: Windows + PHP

SQL Injection to Shell or Backdoor

SQLite Injection to Shell or Backdoor

MS-SQL Console

Upgradig Non-Interactive Shell

Python Input Code Injection

Local Enumeration & Privilege Escalation

https://github.com/sagishahar/lpeworkshop

Check AppLocker Policies

Applocker: Writable Windows Directories

Find Writable Files/Folders in Windows

Check if Powershell Logging is Enabled

Check WinEvent Logs for SecureString Exposure

Check WinEvent for Machine Wake/Sleep times

Audit Policies

Check if LSASS is running in PPL

Binary Exploitation with ImmunityDebugger

Get Loaded Modules

Finding JMP ESP Address

Cracking a ZIP Password

Setting up Simple HTTP server

MySQL User Defined Fuction Privilge Escalation

Requires raptor_udf2.c and sid-shell.c or full raptor.tar:

151B
Open
30KB
archive
Open

Docker Privilege Esclation

Resetting root Password

Uploading Files to Target Machine

TFTP

FTP

CertUtil

PHP

Python

HTTP: Powershell

HTTP: VBScript

Copy and paste contents of wget.vbs into a Windows Shell and then:

HTTP: Linux

NetCat

HTTP: Windows "debug.exe" Method

HTTP: Windows BitsAdmin

Wscript Script Code Download & Execution

Whois Data Exfiltration

Cancel Data Exfiltration

rlogin Data Exfiltration

Bash Ping Sweeper

Brute-forcing XOR'ed string with 1 byte key in Python

Generating Bad Character Strings

Converting Python to Windows Executable (.py -> .exe)

Port Scanning with NetCat

Port Scanning with Masscan

Exploiting Vulnerable Windows Services: Weak Service Permissions

Find File/Folder Permissions Explicitly Set for a Given User

AlwaysInstallElevated MSI

Stored Credentials: Windows

Unquoted Service Path

Persistence via Services

Port Forwarding / SSH Tunneling

SSH: Local Port Forwarding

SSH: Dynamic Port Forwarding

SSH: Remote Port Forwarding

Proxy Tunnel

HTTP Tunnel: SSH Over HTTP

Netsh - Windows Port Forwarding

RunAs / Start Process As

PowerShell

CMD

PsExec

Pth-WinExe

Recursively Find Hidden Files: Windows

Post-Exploitation & Maintaining Access

Browsing Registry Hives

Decrypting RDG Passwords

Remote Desktop Connection Manager passwords can be decrypted on the same computer/account they were encrypted:

Decrypting VNC Password

Creating User and Adding to Local Administrators

Hide Newly Created Local administrator

Creating SSH Authorized Keys

Creating Backdoor User w/o Password

Creating Another root User

Generating OpenSSL Password

Persistent Back Doors

Code Execution / Application Whitelist Bypass

Ieframe.dll

This was inspired by and forked/adapted/updated from Dostoevsky's Pentest Notes.

Last updated