old school hacking : exploiting unix wildcards

46
OLD SCHOOL HACKING Exploiting UNIX Wildcards Emir Fares BELMAHDI [email protected] @ emirfares www.unidees.dz

Upload: unidees-algerie

Post on 12-Apr-2017

350 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Old school hacking : Exploiting UNIX Wildcards

O L D S C H O O L HACKINGExploiting UNIX Wildcards

Emir Fares BELMAHDI

[email protected]@emirfares

www.unidees.dz

Page 2: Old school hacking : Exploiting UNIX Wildcards

FOUR PARTS

About Wildcards Exploiting Wildcards Some useful tricks

Conclusion

Page 3: Old school hacking : Exploiting UNIX Wildcards

ABOUT WILDCARDS

Page 4: Old school hacking : Exploiting UNIX Wildcards
Page 5: Old school hacking : Exploiting UNIX Wildcards

• A character used to substitute for any other character or characters

• Used in regular expressions

• Commonly used in shell commands in Linux and other Unix-like operatingsystems

• In this case wildcards are interpreted by shell before any action

Page 6: Old school hacking : Exploiting UNIX Wildcards

* matches any number of characters in a

filename, including none

? matches any single character.

[ ] Brackets enclose a set of characters,

any one of which may match a single

character

- A hyphen used within [ ] denotes a

range of characters.

~ A tilde at the beginning of a word

expands to the name of your home

directory. If you append another user's

login name to the character, it refers to

that user's home directory.

Page 7: Old school hacking : Exploiting UNIX Wildcards

cat e*

cat te?t.php

cat file[123456789].txt

cat file[1-9].txt

ls ~

ls ~blackfox

Page 8: Old school hacking : Exploiting UNIX Wildcards

EXPLOITING WILDCARDS

Page 9: Old school hacking : Exploiting UNIX Wildcards
Page 10: Old school hacking : Exploiting UNIX Wildcards

Files beginning with (-) character are interpreted as command linearguements

Page 11: Old school hacking : Exploiting UNIX Wildcards

Folder containing some files

File1File2

--help

Page 12: Old school hacking : Exploiting UNIX Wildcards

cat * User executs command

File1File2

--help

Page 13: Old school hacking : Exploiting UNIX Wildcards

cat *

File1File2

--help

cat File1.txt

File content

OK !

Page 14: Old school hacking : Exploiting UNIX Wildcards

cat *

File1File2

--help

cat File2.php

File content

OK !

Page 15: Old school hacking : Exploiting UNIX Wildcards

cat *

File1File2

--help

cat --help

“cat” command help &usage

MAGIC !

Page 16: Old school hacking : Exploiting UNIX Wildcards

USING STRACE

Page 17: Old school hacking : Exploiting UNIX Wildcards

blackfox@dojo:~/wildcards$ strace cat *

Page 18: Old school hacking : Exploiting UNIX Wildcards

blackfox@dojo:~/wildcards$ strace cat *

execve("/bin/cat", ["cat", "File1.txt", "File2.txt", "--help"],[/* 69 vars */]) = 0

Page 19: Old school hacking : Exploiting UNIX Wildcards

blackfox@dojo:~/wildcards$ strace cat *

execve("/bin/cat", ["cat", "File1.txt", "File2.txt", "--help"],[/* 69 vars */]) = 0

1st file 2nd file 3rd file

Page 20: Old school hacking : Exploiting UNIX Wildcards

blackfox@dojo:~/wildcards$ strace cat *

execve("/bin/cat", ["cat", "File1.txt", "File2.txt", "--help"],[/* 69 vars */]) = 0

/bin/cat File1.txt File2.txt --help

1st file 2nd file 3rd file

Page 21: Old school hacking : Exploiting UNIX Wildcards

DEMO

Page 22: Old school hacking : Exploiting UNIX Wildcards
Page 23: Old school hacking : Exploiting UNIX Wildcards

USEFUL TRICKS

Page 24: Old school hacking : Exploiting UNIX Wildcards

CHOWN

Page 25: Old school hacking : Exploiting UNIX Wildcards

blackfox@dojo:~/wildcards$ echo > ''.some_hidden_file''

blackfox@dojo:~/wildcards$ chown user:user .some_hidden_file

blackfox@dojo:~/wildcards$ echo > ''--reference=.some_hidden_file''

Page 26: Old school hacking : Exploiting UNIX Wildcards
Page 27: Old school hacking : Exploiting UNIX Wildcards

CHMOD

Page 28: Old school hacking : Exploiting UNIX Wildcards

blackfox@dojo:~/wildcards$ echo > ''.some_hidden_file''

blackfox@dojo:~/wildcards$ chmod 777 .some_hidden_file

blackfox@dojo:~/wildcards$ echo > ''--reference=.some_hidden_file''

Page 29: Old school hacking : Exploiting UNIX Wildcards
Page 30: Old school hacking : Exploiting UNIX Wildcards

REAL LIFE SCENARIOGETTING ROOT ACCESS

Page 31: Old school hacking : Exploiting UNIX Wildcards

From tar help manual (see: tar --help)

--checkpoint[=NUMBER] : display progress messages every NUMBERth record (default 10)

--checkpoint-action=ACTION : execute ACTION on each checkpoint

Page 32: Old school hacking : Exploiting UNIX Wildcards

executing arbitrary commands with privileges of the user thatruns “tar”

Page 33: Old school hacking : Exploiting UNIX Wildcards

Let's imagine a backup script

Page 34: Old school hacking : Exploiting UNIX Wildcards

DEMO

Page 35: Old school hacking : Exploiting UNIX Wildcards
Page 36: Old school hacking : Exploiting UNIX Wildcards

CONCLUSION

Page 37: Old school hacking : Exploiting UNIX Wildcards

NEVER TRUST INPUTS

Page 38: Old school hacking : Exploiting UNIX Wildcards

Filter file names

Page 39: Old school hacking : Exploiting UNIX Wildcards

AVOID USING WILDCARDS AS A PRIVILEGED USER

(ROOT)

Page 40: Old school hacking : Exploiting UNIX Wildcards

Create a simple user instead

Page 41: Old school hacking : Exploiting UNIX Wildcards

OR

Page 42: Old school hacking : Exploiting UNIX Wildcards

DON'T USE WILDCARDSAT ALL!

Page 43: Old school hacking : Exploiting UNIX Wildcards

Create your own scripts with samefeatures

Page 44: Old school hacking : Exploiting UNIX Wildcards

ALWAYS TEST YOUR SECURITY

Page 45: Old school hacking : Exploiting UNIX Wildcards

Pentesting is important to detect vulnerabilities or misconfigurations

Page 46: Old school hacking : Exploiting UNIX Wildcards

QUESTIONS?

Emir Fares BELMAHDI

[email protected]@emirfares

www.unidees.dz