slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php...

21
that hosting has no rights! :lightning: talk @stuchl4n3k slides https://goo.gl/uessMT `.:+oyhhdmmmmmmmdhhyo+:.` -+shmmmmmmmmmmmmmmmmmmmmmmmmmhs+- ./ymmmmmmmmmmmmmmmmdddmmmmmmmmmmmmmmmmy/. `/hmmmmmmmmmdyo+:-.` `.-:+oydmmmmmmmmmh/` -smmmmmmmmho:. .:ohmmmmmmmms- -ymmmmmmmy+. .+ymmmmmmmy- .smmmmmmdo. .odmmmmmms. +dmmmmmd+` : `+dmmmmmd+ `ymmmmmm+` .: `+mmmmmmy` .hmmmmmh- `. -/:-- -hmmmmmh. -dmmmmmo` `: /. -oyyys:` `ommmmmd- .dmmmmm+ -- +`/: oyyyyyys:----. +mmmmmd. ymmmmm+ `/+++oooooo++++//::--..`` .:/s+y+++syyyyyyyys ` +mmmmmy +mmmmmy -+syyyyyyyyyyyyyyyyyyyssso++++yyyyyyyyyyyyyo- ymmmmm+ `dmmmmm. `-+syyyyyyyyyyyyyyyyyyyssssoyyyyyyyyy/::-` .mmmmmd` /mmmmmo `.:+osyyyyyyys+:...``.-::+yyyyyyyy: ommmmm/ ymmmmm- ``..---.` .+syyyyyyoyyyyy+/---.` -mmmmmy dmmmmm -oyyyyyyyyy +yy-y/:-.` mmmmmd mmmmmh -oyyyyyyyyyy: oyy--/-.`` hmmmmm mmmmmh .+yyyyyyyyyys- yyy+ .. hmmmmm dmmmmm :yyyyyyyyyys/` `yyyy` mmmmmd ymmmmm- `/yyyyyyyyys/` :yyyy- -mmmmmy /mmmmmo `oyyyyyyyys/` :yyyyy+ ommmmm/ `dmmmmm. `oyyyyyys+-` -yyyyyys .mmmmmd` +mmmmmy `oyyyyo/-` :yyyyyyy` ymmmmm+ ymmmmm+ `oys+-. -yyyyyyy. +mmmmmy .dmmmmm+ .-. syyyyyy: +mmmmmd. -dmmmmmo` :yyyyyy: `ommmmmd- .hmmmmmh- +yyyyy/ -hmmmmmh. `ymmmmmm+` +yyyy/ `+mmmmmmy` +dmmmmmd+` /yyy: `+dmmmmmd+ .smmmmmmdo. -sy- .odmmmmmms. -ymmmmmmmy+. `: .+ymmmmmmmy- -smmmmmmmmho:. .:ohmmmmmmmms- `/hmmmmmmmmmdyo+:-.` `.-:+oydmmmmmmmmmh/` ./ymmmmmmmmmmmmmmmmdddmmmmmmmmmmmmmmmmy/. -+shmmmmmmmmmmmmmmmmmmmmmmmmmhs+- `.:+oyhhdmmmmmmmdhhyo+:.`

Transcript of slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php...

Page 1: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

that hosting has no rights!:lightning: talk

@stuchl4n3kslides https://goo.gl/uessMT

`.:+oyhhdmmmmmmmdhhyo+:.` -+shmmmmmmmmmmmmmmmmmmmmmmmmmhs+- ./ymmmmmmmmmmmmmmmmdddmmmmmmmmmmmmmmmmy/. `/hmmmmmmmmmdyo+:-.` `.-:+oydmmmmmmmmmh/` -smmmmmmmmho:. .:ohmmmmmmmms- -ymmmmmmmy+. .+ymmmmmmmy- .smmmmmmdo. .odmmmmmms. +dmmmmmd+` : `+dmmmmmd+ `ymmmmmm+` .: `+mmmmmmy` .hmmmmmh- `. -/:-- -hmmmmmh. -dmmmmmo` `: /. -oyyys:` `ommmmmd- .dmmmmm+ -- +`/: oyyyyyys:----. +mmmmmd. ymmmmm+ `/+++oooooo++++//::--..`` .:/s+y+++syyyyyyyys ` +mmmmmy +mmmmmy -+syyyyyyyyyyyyyyyyyyyssso++++yyyyyyyyyyyyyo- ymmmmm+ `dmmmmm. `-+syyyyyyyyyyyyyyyyyyyssssoyyyyyyyyy/::-` .mmmmmd`/mmmmmo `.:+osyyyyyyys+:...``.-::+yyyyyyyy: ommmmm/ymmmmm- ``..---.` .+syyyyyyoyyyyy+/---.` -mmmmmydmmmmm -oyyyyyyyyy +yy-y/:-.` mmmmmdmmmmmh -oyyyyyyyyyy: oyy--/-.`` hmmmmmmmmmmh .+yyyyyyyyyys- yyy+ .. hmmmmmdmmmmm :yyyyyyyyyys/` `yyyy` mmmmmdymmmmm- `/yyyyyyyyys/` :yyyy- -mmmmmy/mmmmmo `oyyyyyyyys/` :yyyyy+ ommmmm/`dmmmmm. `oyyyyyys+-` -yyyyyys .mmmmmd` +mmmmmy `oyyyyo/-` :yyyyyyy` ymmmmm+ ymmmmm+ `oys+-. -yyyyyyy. +mmmmmy .dmmmmm+ .-. syyyyyy: +mmmmmd. -dmmmmmo` :yyyyyy: `ommmmmd- .hmmmmmh- +yyyyy/ -hmmmmmh. `ymmmmmm+` +yyyy/ `+mmmmmmy` +dmmmmmd+` /yyy: `+dmmmmmd+ .smmmmmmdo. -sy- .odmmmmmms. -ymmmmmmmy+. `: .+ymmmmmmmy- -smmmmmmmmho:. .:ohmmmmmmmms- `/hmmmmmmmmmdyo+:-.` `.-:+oydmmmmmmmmmh/` ./ymmmmmmmmmmmmmmmmdddmmmmmmmmmmmmmmmmy/. -+shmmmmmmmmmmmmmmmmmmmmmmmmmhs+- `.:+oyhhdmmmmmmmdhhyo+:.`

Page 2: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

b4ckd00r pr0b13m?HELP!1337 hAx0r

z

everywhere

!

Page 3: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

b4ckd00r pr0b13m?

Page 4: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

filenoteven +w?

WHAT???

Page 5: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

what everybody agrees...

UNIX PERMISSIONS FTW

Page 6: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

what everybody agrees...

UNIX PERMISSIONS FTW

UNLESS… THE SERVER OWNS THE SCRIPT

Page 7: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

spooky

Page 8: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

am I the only one?

Improper Filesystem Permissions (IF) vuln. is on the Periodic table after all...

Page 9: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

tech support be like…

PID WHAT?

Page 10: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

let’s explain

- Apache server runs with uid 0

- index.php owner is uid 0

- How do I prevent malicious.phpto modify index.php?

Page 11: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

this is simple, right?

- Make Apache run as www-data

- Set the script owner to user-123

- Add user-123 to www-data group

- $ chmod -R 740 user-123/www/*

Page 12: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

provider kernel panic

SORRYNONOT AN

OPEN

KEEP WEBSITE UPDATED

IDGAFDO U EVEN CHMOD, BRO?

ISSUE CAN DO

BASEDIR

NO, WE DO IT RIGHT

Page 13: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,
Page 14: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

let’s automatehostinfo.php- assert that $proc_euid == fileowner(__FILE__)- in 3 more || less reliable ways- source:

github.com/stuchl4n3k/php-hostinfo

Page 15: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

[+] Running PHP 5.6.36-pl0-gentoo (apache2handler) on ...[~] Let's check some functions first:[+] Is 'chmod' available? T[+] Is 'chown' available? T…

[+] Script permissions: 0664[+] Open basedir: '/mnt/data/accounts/n/stuchl4n3k/data/...'[+] Open basedir permissions: 81 0755…

[~] Starting server process owner detection[+] Using POSIX functions to compare file and process owner.

[+] Running as: name=user, uid=81, gid=81, dir=/container/home, shell=/bin/bash[+] Script owner: name=user, uid=81, gid=81, dir=/container/home, shell=/bin/bash

[+] Oh no. This looks bad :( File owner == Process owner

Page 16: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

shared hostings in 2018

Page 17: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,
Page 18: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

except some actually do

(a shared hosting < $4/mo)

+ managed/VPS servers naturally(>> $4/mo)

Page 19: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

- if you run , , , etc.- use VPS/managed servers- know who runs your scripts

- check (add) test results atgithub.com/stuchl4n3k/php-hostinfo

TL;DR

Page 20: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

thank you good OWASP folks!

enjoy your lunchexit(0);

@stuchl4n3kslides https://goo.gl/uessMT

Page 21: slides that hosting @stuchl4n3k has no...let’s explain-Apache server runs with uid 0-index.php owner is uid 0-How do I prevent malicious.php to modify index.php? this is simple,

refs:

- PHP Malware Examination by @TimmehWimmy- Httpd privilege separation