28.10.2014 Views

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Exploiting the Operating System • Chapter 6 297<br />

One of the limitations of using this method is that debug.exe can only build executables<br />

smaller than 64KB in size. This does not prove to be a huge hindrance when you ponder<br />

that a fully working bind shell can be squeezed into fewer than 200 bytes. However, if you<br />

really need to use this technique to upload a larger file, you can split it into chunks, each<br />

one 64KB bytes long, separately upload them, <strong>and</strong> “glue” them together with the DOS copy<br />

comm<strong>and</strong>:<br />

copy /b chunk-1.exe_ + chunk-2.exe_ + … + chunk-n.exe original-file.exe<br />

If you were building the executable using debug, you would probably have combined it<br />

with the copy comm<strong>and</strong> anyway, since debug.exe is built to build .com files. Most automated<br />

tools simply rename the created .com file to .exe after it has been built.<br />

Notes from the Underground…<br />

<strong>SQL</strong> <strong>Injection</strong> Worms<br />

In 2008, at the Black Hat Conference in Las Vegas, this book’s lead author, Justin Clarke,<br />

demonstrated a proof-of-concept <strong>SQL</strong> injection worm that utilized many of the<br />

techniques listed in this chapter. In addition, it utilized a simple scanning engine to<br />

detect <strong>and</strong> exploit Web sites with a Microsoft <strong>SQL</strong> Server back end running in an insecure<br />

configuration (i.e., no privilege escalation was necessary to execute xp_cmdshell).<br />

The worm utilized the debug.exe uploading technique described earlier to<br />

upload a copy of itself to the DBMS, <strong>and</strong> to then execute the remote instance (using<br />

xp_cmdshell) of the worm to continue to spread.<br />

Although this was a proof of concept, it is entirely possible for a vulnerability<br />

such as <strong>SQL</strong> injection to be used in this way as part of a hybrid attack by utilizing <strong>SQL</strong><br />

injection <strong>and</strong> the techniques outlined in this chapter—say, for example, to install<br />

server operating system-level malware.<br />

You can find more details on the worm at www.gdssecurity.com/l/b/2008/08/21/<br />

overview-of-sql-injection-worms-for-fun-<strong>and</strong>-profit/.<br />

A few tools allow you to upload executable files using debug.exe. If you use Windows,<br />

you can try the Automagic <strong>SQL</strong> Injector from Sec-1 Ltd. (www.sec-1.com). It includes a<br />

helper script to first convert a binary to its .scr equivalent, <strong>and</strong> then to facilitate the remote<br />

creation of the .scr file through echo comm<strong>and</strong>s. Automagic also includes a courtesy reverse<br />

User Datagram Protocol (UDP) shell <strong>and</strong> a port scanner (fscan.exe).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!