Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Omega CTF Presentation

Omega CTF Presentation

The presentation of the Omega CTF 2019.

Osanda Malith Jayathissa

July 27, 2019
Tweet

Other Decks in Research

Transcript

  1. RULES • No DDoSing to the servers • You can

    use whatever tools you want • Goal is to exploit the web app and root the box, then capture the flag inside the /root/ folder • Credentials for a temporary VPS to get a reverse shell • [email protected]:ilovelinux123
  2. ABOUT ME Not any geek or any nerd ;-) https://osandamalith.com

    Passionate in Penetration Testing and Reverse Engineering IT Security Consultant at ZeroDayLab, London. Currently holds: OSCE, OSCP, OSWP, CREST CRTPEN, eCRE, eWPTX, eCPPTX, eCPPT Author of few vulnerabilities and 0days. https://www.exploit- db.com/?author=6712 I love to make things, break things and make things that break things ;) DJ at Ministry of Sound, London, UK
  3. SQL Injection Intention Extracting data, Bypassing Auth, Priv Esc, etc

    Source of Vulnerability User input, HTTP headers, second order injection, Files, etc Exploitation Technique Inband, Out-of-Band, Inference
  4. MY ERROR BASED RESEARCHES • Error Based SQL Injection Using

    EXP • https://osandamalith.com/2015/07/15/error-based-sql-injection-using-exp/ • https://www.exploit-db.com/papers/37953 • BIGINT Overflow Error Based SQL Injection • https://osandamalith.com/2015/07/08/bigint-overflow-error-based-sql-injection/ • https://www.exploit-db.com/papers/37733
  5. MYSQL OUT OF BAND HACKING • https://osandamalith.com/2017/02/03/m ysql-out-of-band-hacking/ • https://www.exploit-

    db.com/papers/41273 • https://packetstormsecurity.com/files/14 0832/MySQL-OOB-Hacking.html
  6. VULNERABLE QUERY • $query = "SELECT id,name,join_date,title FROM members WHERE

    name = '" . $member_name . “’;”; • SELECT id,name,join_date,title FROM members WHERE name = ‘Ergo’; • SELECT id,name,join_date,title FROM members WHERE name = ‘Ergo’ UNION SELECT 1,2,3,4; • SELECT id,name,join_date,title FROM members WHERE name = ‘Ergo’ UNION SELECT @@version,2,3,4;
  7. WAFS! if (isset($_REQUEST['member_name']) && $_REQUEST['member_name'] !== '') { $member_name =

    $_REQUEST['member_name']; $member_name = preg_replace("/union|select/i", "", $member_name); $member_name = preg_replace("/into|outfile|dumpfile|[#]|[--]/i", "nope", $member_name); $member_name = preg_replace("(or|and|OR|AND)", "nope", $member_name); $connection = @mysqli_connect(MYSQLHOST, MYSQLUSER, MYSQLPASS, MYSQLDB);
  8. WHEN /OR/i IS FILTERED. • https://osandamalith.com/2017/02 /03/alternative-for- information_schema-tables-in- mysql/ •

    https://www.exploit- db.com/papers/41274 • https://packetstormsecurity.com/fi les/140831/Alternative-For- Information_Schema.Tables-In- MySQL.html
  9. MYSQL PRIVILEGES • File_priv • Enables reading and writing files

    on the server host using the LOAD DATA and SELECT ... INTO OUTFILE statements and the LOAD_FILE() function. A user who has the FILE privilege can read any file on the server host that is either world- readable or readable by the MySQL server. (This implies the user can read any file in any database directory, because the server can access any of those files.) • Enables creating new files in any directory where the MySQL server has write access. This includes the server's data directory containing the files that implement the privilege tables. •
  10. • select File_priv from mysql.user where user = substring_index(user(), '@',

    1) ; • null'unUNIONiOn/**/selSELECTeCt/**/1,File_Priv,3,4/**/from/**/mysql.user/**/ where/**/user=substring_index(user(),'@',1)&&1=‘1
  11. ROOT THE BOX! PRIVILEGE ESCALATION • System and network information

    • User information • Privileged Access / Cleartext credentials • Services • Jobs/Tasks • Installed software version information
  12. SQLI PREVENTION • Use prepared statements and parameterized queries •

    Using PHP Data Objects (PDO) $stmt = $pdo->prepare('SELECT * FROM employees WHERE name = :name'); $stmt->execute(array('name' => $name)); foreach ($stmt as $row) { // Do something with $row } • Supports any database driver and the universal option.
  13. SQLI PREVENTION • Using MySQLi Extension (MySQL Improved) $stmt =

    $dbConnection->prepare('SELECT * FROM employees WHERE name = ?'); $stmt->bind_param('s', $name); // 's' specifies the variable type => 'string' $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_assoc()) { // Do something with $row }