Monthly Archives: August 2013


mysql_real_escape_string won’t magically solve your SQL Injection problems

Edited: 5th Oct 2014 after bug fixing and reader feedback Edited: 6th Oct 2014 after reader feedback I was engaged by an online retailer to test their custom web application CMS and store. I attended their premises and sat down with the tech manager and his lead developer to discuss with them from both a business management and a technical perspective some of the vulnerabilities that should be tested for, as well as to gain a solid understanding of the business needs and logic. When I came on to SQL injection, I was assured by the lead developer that owing to their secure coding practices, SQL injection is completely impossible. All expected user entered integers are cast as integers, and all expected user entered strings are run through mysql_real_escape_string before being passed back to the database. Once code is committed by a developer to the development Subversion server, the lead developer then manually reviews it before deciding to push it live. Great, I thought, it’s certainly a good start. I did point out that this might not always work, but he didn’t seem too phased, and I didn’t want to get too much into a discussion about why or when that might not always work at that stage. […]

By | August 18th, 2013|MySQL, PHP, Security Consultant|13 Comments

SNMP Network Attacks

Neither SNMPv1 and SNMPv2c have any security beyond a plaintext community string. The default community strings for read and write access are ‘public’ and ‘private’ respectively. Some Cisco devices use ‘ilmi’ as the default community string. We can use the tool ‘onesixytyone’ to attempt to brute force the name of the community string from a dictionary: root@pwn:/pentest/enumeration/snmp/onesixtyone# ./onesixtyone -c dict.txt Scanning 1 hosts, 51 communities Cant open hosts file, scanning single host: [public] Linux dev1 2.6.32-5-686 #1 SMP Sun Sep 23 09:49:36 UTC 2012 i686 The community string was successfully brute forced, and is set to the default, ‘public’. We can now use ‘’ to enumerate the host based on this information (some parts truncated to save space) […]

By | August 17th, 2013|Security Consultant|0 Comments

DNS Zone Transfer (AXFR) Vulnerability

A vulnerability exists when DNS servers are [mis]configured to allow for public zone transfers. A zone transfer is literally that – the transfer of an entire zone file, intended primarily for replication and availability between multiple DNS servers. A DNS zone transfer is attempted as follows: dig axfr <domain> @<DNS server> […]

By | August 16th, 2013|Security Consultant|2 Comments

PHP Local and Remote File Inclusion (LFI, RFI) Attacks

PHP supports the ability to ‘include’ or ‘require’ additional files within a script. If unsanitized data is passed to such functions, an attacker may be able to get remote code execution access to the server. A typical include block might look something like this: <?php require("config/"); require("lib/db.lib.php"); require("lib/parser.lib.php"); include("contrib/users/user.contrib.php"); die("This is a test"); ?> Now, it’s also possible to dynamically require or include files based on variables or user input, say for example: […]

By | August 15th, 2013|Linux, PHP, PHP, PHP Articles, Security Consultant|0 Comments

MySQL Root to System Root with lib_mysqludf_sys for Windows and Linux

Once a MySQL database server has been compromised at root level, it’s often possible to escalate this access to full system level access using User Defined Functions (UDFs). We may have MySQL root access but not system root access for a number of reasons including having a shell account on the target whilst MySQL’s root user has been left unpassworded by default, or alternatively gaining access via SQL injection through a web application connecting to the database as root, which is something I see far too often. Firstly, you’ll want to check out a copy of sqlmap. For this attack you’ll want to browse to the ‘udf’ directory and select the appropriate library depending on your target platform: udf/mysql/linux/32/ udf/mysql/linux/64/ udf/mysql/windows/32/lib_mysqludf_sys.dll udf/mysql/windows/64/lib_mysqludf_sys.dll The steps for escalation on both Windows and Linux are the same. Firstly, we need to get a copy of the correct library on to the target machine in a known location – this could be by uploading to a user account we have access to, or uploading via a website image/file upload, or anonymous FTP account. The second step is issuing a SQL query to load this file in to a newly created table row. Third, we then want to dump that table row out to a new file in either the ‘/usr/lib’ directory or the ‘c:\windows\system32’ directory depending on whether we are on Linux or Windows respectively. The reason we need to do this, is that our regular web application or user account does not have permission to create files in these directories, however the MySQL root user does. Next, we want to instruct MySQL to create a new function to point to the code in our malicious library. Lastly, we execute this new function with arbitrary system commands that we wish to run. […]

By | August 13th, 2013|MySQL, Security Consultant|8 Comments

First Steps in Oracle Penetration Testing

In this article, I’ll discuss a range of basic Oracle 9 testing principles from the SID and account enumeration to query execution and finally, you guessed it, remote code execution. If you’re looking for professional oracle penetration testing, please contact me. Firstly, we’ll check to see that TCP port 1521 which is the Oracle Net Listener is open using nmap: nmap -p 1521 Oracle Net Listener Nmap Once done, we can use the ‘status’ and ‘version’ commands to get more information, using ‘’ from a tool called ‘oracle_checkpwd’: ./ version -h ./ status -h tnscmd Version and Status […]

By | August 12th, 2013|Security Consultant|2 Comments

Windows Null Session Enumeration

Null Sessions are a ‘feature’ of Windows allowing an anonymous user to connect to the IPC$ share and enumerate certain information. We can connect to this under Windows using the commands: net use \\IP_ADDRESS\ipc$ "" /user:"" net use or from Linux with: rpcclient -U "" IP_ADDRESS Once connected and at the “rpcclient $>” prompt, we can issue a ‘?’ to look at the supported commands. The most interesting are ‘enumdomusers’, ‘netshareenum’, ‘netshareenumall’ and ‘querydominfo’. Here’s the output against a sample lab machine: rpcclient $> enumdomusers cli_pipe_validate_current_pdu: RPC fault code DCERPC_FAULT_OP_RNG_ERROR received from host! user:[admin] rid:[0x3ef] user:[Administrator] rid:[0x1f4] user:[npn] rid:[0x3f0] user:[Guest] rid:[0x1f5] rpcclient $> querydominfo cli_pipe_validate_current_pdu: RPC fault code DCERPC_FAULT_OP_RNG_ERROR received from host! Domain: WINSRV Server: Comment: Total Users: 13 Total Groups: 1 Total Aliases: 0 Sequence No: 899 Force Logoff: -1 Domain Server State: 0x1 Server Role: ROLE_DOMAIN_PDC Unknown 3: 0x1 rpcclient $> […]

By | August 10th, 2013|Uncategorized|2 Comments

Accessing and Hacking MSSQL from Backtrack Linux

In this article, we’ll cover connecting to a Microsoft SQL (MSSQL) server from the Backtrack/Linux command line, executing system commands through the ‘sa’ or other administrative account, and finally exploiting the ‘sa’ account through metasploit. To start with, let’s cover a quick HOWTO on getting an MSSQL client working under Backtrack/Linux. We’ll need freetds and sqsh for this: apt-get install sqsh freetds-bin freetds-common freetds-dev Once done, we’ll need to edit /etc/freetds/freetds.conf, and append the following to it: [MyServer] host = port = 1433 tds version = 8.0 And lastly, we’ll edit ~/.sqshrc: \set username=sa \set password=password \set style=vert […]

By | August 10th, 2013|Linux, Security Consultant|1 Comment