Wednesday, November 11, 2009

Abuse Citrix and own the domain

Little Bobby Tables is growing up quickly, he is now performing a Citrix break-out assessment: basically the scope of the penetration test consists of trying to execute applications that he is not allowed to after logging to a Citrix MetaFrame or similar environment. Usually a screenshot with a command prompt showing the output of ipconfig /all is enough proof to the Client that you have successfully broken out of the restricted environment and the party can roll out onwards. There are many tutorials to achieve this goal and I will not repeat them.

Assume that little Bobby asked for help to old uncle Google, found the above mentioned tutorials along with some videos and successfully broke-out of the environment while
circumventing Windows GPO/SRP and other security mechanism getting a command prompt or even an unrestricted RDP session onto the box.
He now feels good, is excited, and wants the Client to know that in about half an hour he broke-out of the environment. Bobby then calls who paid two or more days of assessment to let him know that he is done already with the initial work and asks for permission to go further with the test to demonstrate how dangerous a malicious attacker could be in such a scenario. The Client agrees.. in the end he's paid for the rest of the man days and wants to make the best usage out of them by finding the flaws within his whole network.

What is next?

Little Bobby knows about the beauties of Windows' net command and put it to great use. He enumerates machines within the Windows domain, identifies the primary domain controller (PDC), list local and domain users from the PDC/BDC, etc.. all in all gather as much information as possible about the owned system and its network perimeter.

He can also upload his own tools easily by mapping his local shared hard-drive via Citrix XenApp (the new Citrix ICA client for Windows) onto the target Citrix environment, by copy 'n paste and debug.exe trick, via muudecode/uuencode, or whatever working technique, depending how hardened Citrix is.

First goal now is to escalate privileges to a highly privileged local user like Administrator or LOCAL SYSTEM assuming that the user is not within the Administrators group already. There exist several techniques to do so. Once done it is game over, you own that system completely.

What about logging onto other systems?

Surely little Bobby won't stop here. He wants to own all the servers within the network perimeter, above all the PDC and other infrastructure critical servers, like database servers.

He dumps user's password hashes (Security Accounts Manager), LSA secrets, passwords cache, protected storage, reversible encryption storage, passwords history and
current logon sessions tokens. PWDumpX and Cain&Abel are handy tools along with the others linked.
Now he has collected credentials of many other users: either plain-text or NTLM credentials for all local users, users who logged onto the box since last reboot, users logged in at the very same time, and users used to start services.
Hopefully among these credentials, little Bobby has got the hash of a domain user. If he gets very lucky, it will be a domain administrator. Again, net is your friend to check so.


Now Bobby resurrect the list of enumerated hosts, tries to discover more hosts on the network perimeter via ping sweep, ARP scan and network traffic sniffing with a bunch of uploaded tools. He now has a huge list of hosts to own. On top of the list there are the domain controllers and eventually the database servers!

At this point he has a list of hosts in one text file and a single file collecting the above dumped hashes (output of PWDumpX et all).

Own the LAN: the common way

Little Bobby could crack the dumped
password hashes and try to login over SMB or RDP with the cracked plain-text credentials onto the other systems, one by one. To login and execute commands over SMB onto another system he could upload to the Citrix box and run a single executable file, PsExec.

Another tool can be handy, smbshell, a pre-compiled NASL script, but it requires the nasl interpreter and a bunch of other Nessus libraries to run, not very convenient in the above scenario. Nevertheless, an advantage over PsExec is that it accepts also the NTLM hash of the password, so there is no need to crack the password to login over SMB. Like PsExec, it can be used to login onto one system at a time.

Isn't there anything quicker to check usefulness of dumped hashes?

Own the
LAN: the quickest way

Our lazy little Bobby heard about a new open source multi-threaded tool called keimpx developed in Python that can be used to quickly check for the usefulness of credentials across a network over SMB.
Credentials can be:
  • Combination of user / plain-text password.
  • Combination of user / NTLM hash.
  • Combination of user / NTLM logon session token.
If any valid credentials have been identified across the network after its attack phase, the user is asked to choose which host to connect to and which valid credentials to use, then Bobby will be prompted with an interactive SMB shell where he can:
  • Navigate through the available shares: list, upload, download files, create, remove files, etc.
  • Deploy and undeploy his own service (for instance, a backdoor listening on a TCP port for incoming connections).
  • List users' details and domains.
  • Read/write/delete registry keys (soon).
  • Spawn an interactive command prompt like PsExec can do (soon).
This tool does the trick and is the quickest way to identify in a single shot which dumped hashes work on which machines of the network perimeter without the need to crack the hashes. Moreover, it can also be used to login over SMB onto the systems where valid credentials have been spotted and perform the above mentioned operations.

keimpx is a work in progress tool and feedback is more than welcome
!

Remember that:
  • Many users share the same password across multiple machines, this might include also Administrator, in such a case you are local administrator on most, if not all, the systems of the network perimeter.
  • You might have been lucky enough to dump also a domain administrator password hash (for instance, via LSA secrets dump, Pass-the-Hash's whosthere.exe or incognito) so you totally own the domain and can login on all systems of the network with the highest global privileged user.
Little Bobby Tables can now call the Client and let him know that he has access to most (if not all) the network's machines.

Own the
LAN: the hardcore way

If no dumped credentials worked on any other system then Bobby needs to get his hands dirty.

If the Citrix environment has direct access to the Internet he could initiate an out-of-band connection with his own local system to pivot traffic from the local system to the Citrix machine network perimiter. This can be achieved, for instance, via Metasploit's Meterpreter. From this point on he can launch any Metasploit module against others boxes to portscan them, perform a vulnerability assessment or exploit security flaws.
Elsewhere, if the Citrix environment has not direct access to the Internet, Bobby can upload a port scanner and his suite of exploits to scan and own them all.

Tuesday, November 10, 2009

CONFidence 2009 2.0

My friend Guido Landi and I have been selected as speakers for CONFidence 2009 2.0 conference. We are scheduled to present on November 20.

We will be presenting a slightly updated version of our presentation titled Expanding the Control Over Operating System From the Database. The new abstract is as follows:
Using a database (MySQL, PostgreSQL and Microsoft SQL Server), either via a SQL injection or via direct connection, as a stepping stone to control the underlying operating system can be achieved. There is much to say on operating system control by owning a database server: Windows registry access, anti-forensics technique to establish an out-of-band stealth connection, buffer overflow exploitation with memory protections bypass and custom user-defined function injection. These topics and more will be highlighted during the presentation.
The Conference will take place on November 19 - 20, 2009 at
Femina Cinema in Warsaw (Poland), don't miss it if you can!

Saturday, September 26, 2009

Expanding the control over the operating system from the database

On Tuesday I came back from Barcelona (Spain) where I gave a talk with my friend Guido Landi at SOURCE Conference 2009, met some very smart people, had good chats, fun times too and ate amazing spanish tapas with tasty local red wine!

Thanks SOURCE Barcelona 2009 team for organizing such a great event and giving me the opportunity to come over!

Our presentation slides are online on Slideshare. You
can also read them below.

I also released sqlmap 0.8 release candidate 1
with all of the new features described during my presentation at the Conference. You can also checkout the source code from the sqlmap Subversion repository.
$ svn checkout https://svn.sqlmap.org/sqlmap/trunk/sqlmap/ sqlmap

Monday, September 7, 2009

SOURCE Barcelona 2009

My friend Guido Landi and I have been selected as speakers for SOURCE Barcelona 2009 conference. We are scheduled to present on September 21.

Our presentation is titled Expanding the Control Over Operating System From the Database and the abstract is as follows:
Using a database, either via a SQL injection or via direct connection, as a stepping stone to control the underlying operating system can be achieved. There is much to say on operating system control by owning a database server: Windows registry access, anti-forensics techniques and custom user-defined function injection. These topics and more will be highlighted during the presentation.
The Conference will take place on September 21 - 22, 2009 at Museu Nacional D’art de Catalunya in Barcelona (Spain), don't miss it if you can!

Saturday, July 25, 2009

sqlmap 0.7 released

Today I released sqlmap version 0.7.

Along all the takeover features introduced in sqlmap 0.7 release candidate 1, some of the new features include:
  • Adapted Metasploit wrapping functions to work with latest 3.3 development version too.
  • Adjusted code to make sqlmap 0.7 to work again on Mac OSX too.
  • Reset takeover OOB features (if any of --os-pwn, --os-smbrelay or --os-bof is selected) when running under Windows because msfconsole and msfcli are not supported on the native Windows Ruby interpreter. This make sqlmap 0.7 to work again on Windows too.
  • Minor improvement so that sqlmap tests also all parameters with no value (eg. par=).
  • HTTPS requests over HTTP proxy now work on either Python 2.4, 2.5 and 2.6+.
Complete list of changes at http://sqlmap.sourceforge.net/doc/ChangeLog.

If you have any feedback feel free to contribute!

Tuesday, June 30, 2009

Back from Lisbon, Portugal

Last week-end I was in Lisbon (Portugal) speaking at the 2nd Digital Security Forum.
The Conference was a blast! Very well organized, good location, warm people and some interesting speeches too. I look forward to attend at the next.

Thanks to the guys at PontoSI and other sponsors for organizing such a great event.

As usual, I published the slides on SlideShare.

Wednesday, June 10, 2009

Digital Security Forum 2009

I have been invited to speak at the 2nd Digital Security Forum in a couple of weeks time.

I will present an updated version of my slides SQL injection: Not Only AND 1=1. The abstract is once again as follows:

The presentation has a quick preamble on SQL injection definition, sqlmap and its key features.

I will then illustrate into details common and uncommon problems and respective solutions with examples that a penetration tester faces when he wants to take advantage of any kind of web application SQL injection flaw on real world web applications, for instance SQL injection in ORDER BY and LIMIT clauses, single entry UNION query SQL injection, specific web application technologies IDS bypasses and more.

The Conference will take place on June 26 - 27, 2009 at Hotel Olissippo Oriente in Lisbon (Portugal).
If you are around, it's an occasion to catch up and share ideas on application security, see you there!

Tuesday, June 2, 2009

sqlmap in Ubuntu package repository

Ubuntu developer James Westby has been very fast to pick sqlmap up from Debian repository, it is now officially available as a package "for human beings" on Ubuntu Karmic, the next stable release!

Wednesday, May 27, 2009

PaulDotCom video on sqlmap

During PaulDotCom Security Weekly - Episode 152 on May 14, 2009, John Strand discussed about sqlmap in a video hosted on vimeo.

I think the video is worth watching for someone interested in having a quick overview on very few sqlmap features, but going through the users' manual and the users' mailing list archive offer much more technical insight on the tool and the vulnerability itself.

Follows my comments on the video:
  • Minute 0:20 - "[...] one of the reasons why I think it is better than commercial tools it's quite simply because of its flexibility [...]".
In practice only the less flexible enumeration option has been demonstrated (--dump-all) rather than focusing on the fact that it has plenty of options to automatically enumerate/dump specific information like for example test if session user is DBA, retrieve only current user password hash, dump only a range of entries from a table or even only some columns, etc. All of these features are illustrated with examples in the sqlmap user's manual.
Also, he is showing sqlmap user's manual from the site (0.7rc1) but during the demonstration he is using sqlmap 0.6.4.
  • Minute 7:10 - "[...] there has been a lot of tools that do PHP [...]. This tool also has the capability of doing ASP [...]".
SQL injection is not a matter of the web application language. It is a matter of lack of security driven development best practices put in place, lack of proper input sanitization, lack of proper web application firewall and so on. The concept exposed by John here is wrong and can lead the newbie user to not understand the flaw properly.
Also, from his words it seems that a SQL injection tool is more powerful if it "does" more web scripting languages: needless to say that this is totally wrong because as soon as the tool engine is written and working, the SQL injection tool does not care at all what is the language in which the application is written. On the other hand, something that shall be considered when evaluating a SQL injection tool is its support for different back-end DBMS software which implies support for different SQL dialects because the SQL statements depend upon the database software / version / session user privileges. Again, not on the front-end language.
  • Minute 7:26 - "[...] a wonderful error [...] tools crash anytime [...]".
If you take a look at the Python traceback, you see why the tool raises the exception. It's because sqlmap saves everything it fetches into the output/ subfolder. John probably run the tool at first place as a privileged user so the output/testasp.acunetix.com/log has been created with 644 privileges, owned by root and since he runs the tool for the second time as normal user (apparently argotek) it's obvious that it "crashes" with a Permission denied exception.
  • Minute 7:39 - "[...] going off Microsoft SQL back-ends as well as part of ASP".
Good point, but Microsoft SQL Server can be the back-end DBMS also for a front-end application in PHP or any other language that has built-in or external connectors to support connections to such DBMS.
  • Minute 7:50 - --sql-shell has been recently fixed. Give it a try to the latest development version from subversion repository. However, good point and well described here.
  • Minute 8:35 - Thanks for pointing out the user several times to RTFM.
  • John only mentioned about the takeover functionality at the beginning of the video while going through the user's manual pages.
    What about a video demonstrating in practice the new features to takeover the underlying file system and operating system from the SQL injection vulnerability? To give you an idea, just grab sqlmap from subversion repository and read more on my presentations' slides, whitepaper and video.

Monday, May 25, 2009

EUSecWest 2009

I have been selected as a speaker for EUSecWest 2009! I am scheduled to talk on May 28.

I will be presenting a cut down version of my Black Hat Europe talk due to the shorter time available. However, the most interesting aspects of the research will be covered along with the practical demonstrations with the latest
sqlmap development version.

The Conference will take place on May 27 - 28, 2009 at the Sound Club in central London (United Kingdom) and the schedule looks very promising, don't miss it if you can!