OverTheWire - Natas

Info

Levels: http://natas{LEVEL}.natas.labs.overthewire.org Source: http://natas{LEVEL}.natas.labs.overthewire.org/index-source.html Passwords: /etc/natas_webpass/natas{LEVEL}

Natas 0 -- Basic Auth

➜ curl http://natas0.natas.labs.overthewire.org -u 'natas0:natas0' -s | sls password

You can find the password for the next level on this page.
<!--The password for natas1 is 0nzCigAq7t2iALyvU9xcHlYN4MlkIwlq -->

Natas 1 -- HTML Comment

➜ curl http://natas1.natas.labs.overthewire.org -u 'natas1:0nzCigAq7t2iALyvU9xcHlYN4MlkIwlq'
...
You can find the password for the
next level on this page, but rightclicking has been blocked!

<!--The password for natas2 is TguMNxKo1DSa1tujBLuZJnDUlCcUAPlI -->
...

Natas 2 -- Files Disclosure

Natas.png

Natas 3 -- robots

Natas 4 -- Referer

Natas 6 -- Information Disclosure

Natas-1.png

Natas 7 -- LFI

http://natas7.natas.labs.overthewire.org/index.php?page=homearrow-up-righthttp://natas7.natas.labs.overthewire.org/index.php?page=aboutarrow-up-right

Natas 8 -- Encode Reverse

Natas 9 -- Command Injection

Natas-2.png

Natas 10 -- Command Injection (2)

Natas 11 -- Crib

Natas-3.png

Known-plaintext attack tool for XOR-encrypted dataarrow-up-right

Natas-4.png

Somewhat later I realized that we already know the plaintext, so you can take the original cookie where bgcolor is #FFFFFF, then use {"showpassword": or smaller json to do XOR and leak the key. As you can see eDWo keeps repeating meaning it's the key.

Natas-30.png

Natas 12 -- Upload webshell

Natas-5.png

Natas 13 -- Upload image webshell

Natas 14 -- SQLi (Basic)

Natas-6.png

Natas 15 -- SQLi (Blind)

Natas-7.png
circle-info

Note: For some reason SUBSTR function was not case sensitive?... BINARY made it case sensitive again.

Natas 16 -- Command Injection (Blind)

Natas-8.png

Natas 17 -- SQLi (Timed)

Natas-9.png
circle-info

Note: For some reason SUBSTR function was not case sensitive?... BINARY made it case sensitive again.

Natas 18 -- Predictable Session ID

Natas-10.png

Natas 19 -- Predictable Session ID (2)

Natas-11.png

Natas 20 -- Custom SESSID Logic Vulnerability

Natas-12.png

myread code introduces vulnerability by changing the logic, especially when it assigns the key:value pairs to session from data, which is taken from username.

No sanitization allows us to inject newline and then admin 1 which is used to check if we are admin and get password.

Natas-13.png

http://natas21-experimenter.natas.labs.overthewire.orgarrow-up-right

Natas-14.png

Natas 22 -- Don't Follow Redirect

Natas 23 -- String/Integer Comparison

Natas-15.png

The submitted password should contain iloveyou and should be greater then 10 (the value, not length).

Natas 24 -- strcmp bypass

PHP strcmp Bypass – Introductionarrow-up-right

Natas 25 -- Log poison -> LFI -> RCE

Natas-16.png

Natas 26 -- Deserialization Attack

Natas-17.png

Logger class is just sitting there and no instance is spawned, which is odd. Cookies are desterilized from base64 decoded data and PHP has a known vulnerability in that field:PayloadsAllTheThings / Insecure Deserialization / PHP Deserializationarrow-up-right

Natas-18.png

Natas 27 -- Whitespace Injection

Natas-19.png

createUser restricts the creation of user which has spaces, but later it cuts down length to 64. We can create username like natas28<SPACES><ANY_CHAR>, essentially a sandwich that will make spaces bypassable. But why do we need spaces? dumpData function takes our username, trims it and then performs query (admin -> admin).

Natas 28 -- PKCS#7

Natas-20.png

URL Decode the search.php query param

If we remove few characters and send request error gets triggered:

Natas-21.png

Do some fuzzing to analyze the encryption method:

The repeating patters have been separated by space, as it seems only middle part gets changed. Probably because query is like SELECT field FROM table WHERE field LIKE '<INPUT>%' where only our input changes the query.

Fuzzing with {'query': 'AAAAAAAAAA' + char} reveals mostly same results and the repeating pattern is a clear indicator that ECB encryption.

Electronic Code Book (ECB) is a simple mode of operation with a block cipher that's mostly used with symmetric key encryption. srcarrow-up-right

Search for

Each block length is 16

The first and last 2 blocks seems to be always repeating and middle part is always changing. As we mentioned we can guess partial query, for the last part it's probably like ORDER BY rand() LIMIT 3 because on successful result we get only 3 jokes, but different jokes on each request.

Also notice that 5f22a727f625419a466f9af53891f9b2 is repeated, it's result of 13 "A"s

Anyway, why the fuck are we discussing encryption? Well this would have been too easy if we could just insert a quote and then malicious SQL, right? The quotes and other special characters are escaped, most probably addslashes is used on backend. The question is, how do you escape the escape? The encryption! Because of the nature of block cipher we can inject quote, but the new character will be in the next block if we overflow the block and we can rewrite previous block with "good block".

circle-info

Note: I thought the repeat size was 12, but it was 9.

Natas 29 -- Perl RCE

Natas-22.png

http://natas29.natas.labs.overthewire.org/index.pl?file=perl+undergroundarrow-up-right

The usual LFI doesn't work, but now instead of PHP we are working with Perl. Perl has "unique" properties when it comes to file handling, such as if filename ends with | after that it's interpreted as shell command and essentially allows RCE. We can also inject Null Byte to block any characters afterwards.

natas word is blacklisted, but since we are in bash we can use globbing to bypass that. ? means any single character at that position.

Natas 30 -- Perl quote

Natas-23.png

StackExchange > Security > Is this Perl database connection vulnerable to SQL Injectionarrow-up-righthttps://metacpan.org/pod/DBI#quotearrow-up-righthttps://metacpan.org/pod/DBI#type_info_allarrow-up-right

Natas 31 -- ARGV is evil, LFI

Natas-24.png

https://perldoc.perl.org/perlsecarrow-up-rightRe: The Perl Jam 2: <"ARGV"> is evilarrow-up-right

Natas-25.png

Natas 32 -- ARGV is evil, RCE

Natas-26.png

Source code is the same.

Natas 33 -- phar:// deserialization

Natas-27.png

md5_filearrow-up-right function is a bit suspicious.

There is a file upload vulnerability that leads to command execution. #27arrow-up-rightphar:// deserializationarrow-up-right

Phar files (PHP Archive) files contain meta data in serialized format, so, when parsed, this metadata is deserialized and you can try to abuse a deserialization vulnerability inside the PHP code.The best thing about this characteristic is that this deserialization will occur even using PHP functions that do not eval PHP code like file_get_contents(), fopen(), file() or file_exists(), md5_file(), filemtime() or filesize().

First upload the PHP script that we want to execute and change the filename:

Natas-28.png

Second upload the phar file and change the filename:

Natas-29.png

Credentials

User
Password

natas0

natas0

natas1

0nzCigAq7t2iALyvU9xcHlYN4MlkIwlq

natas2

TguMNxKo1DSa1tujBLuZJnDUlCcUAPlI

natas3

3gqisGdR0pjm6tpkDKdIWO2hSvchLeYH

natas4

QryZXc2e0zahULdHrtHxzyYkj59kUxLQ

natas5

0n35PkggAPm2zbEpOU802c0x0Msn1ToK

natas6

0RoJwHdSKWFTYR5WuiAewauSuNaBXned

natas7

bmg8SvU1LizuWjx3y7xkNERkHxGre0GS

natas8

xcoXLmzMkoIP9D7hlgPlh9XD7OgLAe5Q

natas9

ZE1ck82lmdGIoErlhQgWND6j2Wzz6b6t

natas10

t7I5VHvpa14sJTUGV0cbEsbYfFP2dmOu

natas11

UJdqkK1pTu6VLt9UHWAgRZz6sVUZ3lEk

natas12

yZdkjAYZRd3R7tq7T5kXMjMJlOIkzDeB

natas13

trbs5pCjCrkuSknBBKHhaBxq6Wm1j3LC

natas14

z3UYcr4v4uBpeX8f7EZbMHlzK4UR2XtQ

natas15

SdqIqBsFcz3yotlNYErZSZwblkm0lrvx

natas16

hPkjKYviLQctEW33QmuXL6eDVfMW4sGo

natas17

EqjHJbo7LFNb8vwhHb9s75hokh5TF0OC

natas18

6OG1PbKdVjyBlpxgD4DDbRG6ZLlCGgCJ

natas19

tnwER7PdfWkxsG4FNWUtoAZ9VyZTJqJr

natas20

p5mCvP7GS2K6Bmt3gqhM2Fc1A5T8MVyw

natas21

BPhv63cKE1lkQl04cE5CuFTzXe15NfiH

natas22

d8rwGBl0Xslg3b76uh3fEbSlnOUBlozz

natas23

dIUQcI3uSus1JEOSSWRAEXBG8KbR8tRs

natas24

MeuqmfJ8DDKuTr5pcvzFKSwlxedZYEWd

natas25

ckELKUWZUfpOv6uxS6M7lXBpBssJZ4Ws

natas26

cVXXwxMS3Y26n5UZU89QgpGmWCelaQlE

natas27

u3RRffXjysjgwFU6b9xa23i6prmUsYne

natas28

1JNwQM1Oi6J6j1k49Xyw7ZN6pXMQInVj

natas29

31F4j3Qi2PnuhIZQokxXk1L3QT9Cppns

natas30

WQhx1BvcmP9irs2MP9tRnLsNaDI76YrH

natas31

m7bfjAHpJmSYgQWWeqRE2qVBuMiRNq0y

natas32

NaIWhW2VIrKqrc7aroJVHOZvk3RQMi0B

natas33

2v9nDlbSF7jvawaCncr5Z9kSzkmBeoCJ

natas34

j4O7Q7Q5er5XFRCepmyXJaWCSIrslCJY

Last updated