Before you read any further note, I will not be including the original hack file, simply due to peoples stupidity in putting this on a production environment to play with, if you use the code you do so at your own risk, and by reading this blog entry / using the code provided you agree to accept all liability upon yourself for your own actions. Don’t be an idiot.
Around 10 days ago I came across this seemingly innocuous little file.
What I am going to cover in this entry is dissecting the ‘payload’ and not so much the web app in question or methods used to compromise it,
Whereas I will not at this time provide the original file, I will provide you with the md5 and sha1 hashes of the file so you can check it’s not lurking on your systems:
md5: 9ee3e6523d154114460d320477a8665a
sha1: 9c64fecea5620d70a716bbd74f6e89612a4a79c7
The bit we are interested in is the last line of the file:
Were you to run this line you would get

Confused yet? now I can appreciate the thinking behind packing a payload to avoid detection, but in this case the payload is packed 12 times, and no before you ask I did not manually run each returned statement to find this out.
Enter Python-Fu:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| #!/usr/bin/env python
# saiweb.co.uk payload unpack script 26/05/2010
# copy the eval(gzinflate()) line to payload.raw, place in same directory as this file.
"""
Copyright (C) 2010 Buzz saiweb.co.uk.co.uk
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional Terms as Per section 7
Attribution:
Redistribution/Reuse of this code is permitted under the GNU v3 license, as an additional term ALL code must carry the original Author(s) credit in comment form.
"""
import base64, zlib, re, sys
def main():
print 'Running ...'
f = open('payload.raw')
php = f.read()
f.close()
iteration = 0
while re.search('eval\(gzinflate\(base64_decode\(\'',php):
iteration += 1
print 'Iteration: %d' % iteration
raw = re.sub('eval\(gzinflate\(base64_decode\(\'','',php)
raw = re.sub('\'\)\)\);','',raw)
gstring = base64.b64decode(raw.strip())
php = zlib.decompressobj().decompress('x\x9c' + gstring)
#print payload
#sys.exit()
print php
if __name__ == '__main__':
main() |
Copy the first payload lines into a file named payload.raw, take the above code and copy it into a file named dissect.py.
When dissect.py is run you will get the following output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| python ./dissect.py
Running ...
Iteration: 1
Iteration: 2
Iteration: 3
Iteration: 4
Iteration: 5
Iteration: 6
Iteration: 7
Iteration: 8
Iteration: 9
Iteration: 10
Iteration: 11
Iteration: 12
<?php
... |
As such you may want to run it using the following command:
1
| python ./dissect.py > r57.php |

And what you will find after unpacking 12 times in total, the “payload” is the r57shell, this script is an information gathering tool and pseudo shell, meaning it will run any command on the host server that php can, providing in most cases ssh esq access to the exploited host, allowing you to do pretty much anything you wanted at this point, some of the features also include /etc/passwd /etc/shadow dumping, aswell as searching for a tirade of common file *.sql* admin* etc, it’s a one stop script for information gathering on a LAMP/WAMP based host.
Defense: modify php.ini to disable eval(), exec, shell_exec and all none essential functions.
And of course, ensure your web apps are patched and up to date as well as the host they are running on.
Tags: dissecting, hack, php, python, r57, r57shell
No Comments »
Posted by: Buzz in hacking
Or, as one of my colleagues this morning said, firmware programming which in the literal sense of the word I suppose it is firmware.
I’ve decided as some of my twitter followers may already know to produce a library / framework for the teensy arduino which is available from subversion here: http://svn.saiweb.co.uk/branches/teensy/trunk/ under the GPL v3 license
At the time of writing I have worked through this tutorial on operating an RGB LED.
I’ve taken the examples an reworked them into a re-usable library incorporating a multitude of functions,


Being as I have all the parts to work through the full set of tutorials at pjrc, the library will be first updated to incorporate these examples, once complete I’ll be heading over to the HID programming aspect, and there will be a library for a plethora of “fun” applications
Tags: arduino, library, teensy
No Comments »
Posted by: Buzz in Mac

In one of those you don’t believe it until you have seen it moments not bad for a mac book pro with only a 350gb HD …
Tags: bytes, machine, peta, time, wtf
No Comments »
Posted by: Buzz in flowplayer
Changelog
TRAC tickets closed: #68 #61 #8 #56 #7 #60
Additionally added real time updates to the colour wheel and demo player when editing the hex code manually, updated flowplayer to version 3.1.5
This code is in final review in dev subversion, and will be pushed to the wordpress plugins SVN tomorrow time allowing.
Tags: flowplayer, wordpress
4 Comments »
Posted by: Buzz in Linux
Strangely I’ve had some people reporting issues with being prompted for a username and password when accessing files on svn.saiweb.co.uk
it would appear in mod_dav_svn-1.4.2-4.el5_3.1 that this directive: AuthzSVNNoAuthWhenAnonymousAllowed
now defaults to OFF, well that was a p.i.t.a trying to track down, having never seen that directive in ANY of the documentation …
Anyway pass this on to other facing the same issue.
Tags: AuthzSVNNoAuthWhenAnonymousAllowed, broken, fubar, fucked, mod_authz_svn, mod_dav_svn, svn, wtf
No Comments »
Posted by: Buzz in Linux
The default install of VI is very basic, and being as I spend a lot of my time in there I find syntax highlighting invaluable, to get this however you will need the vim-enhanced package.
So run the following to install this package and setup an alias for vi.
1 2 3 4
| yum install vim-enhanced
echo "alias vi='/usr/bin/vim'" >> ~/.bashrc
echo "syntax on" >> ~/.vimrc
alias vi='/usr/bin/vim' |
And you’re done:
Tags: CentOS, highlight, rhel, syntax, vi, vim-enhanced
No Comments »
Posted by: Buzz in Mac
Having little time to update my blog, I’ve been updating a wiki I keep with various tidbits, so I thought I might as well share a few, they will be appearing on here over the next few days.
First off you will want to open the “Terminal” application, not so much a play on words it is really called Terminal.
Applications -> Utilities -> Terminal
1
| showmount -e aaa.bbb.ccc.ddd |
Where aaa.bbb.ccc.ddd is the IP or FQDN of your NFS server, this command will show a list of mountable exports on the device.
1
| sudo mount -t ntfs aaa.bbb.ccc.ddd:/exported/path ~/Desktop/nfs_folder |
If you look on your desktop you will now see that the folder icon has changed to an aliased drive icon 
NOTE: These changes will not persist through a reboot, I have not yet found a way of doing this short of some apple / automator script to remount the drives on startup.
Tags: exports, Mac, mount, nfs, osx
2 Comments »
Posted by: Buzz in flowplayer
A user contributed patch from James Partington can be found Here
When applied you can specify a splash image to user and your media by seperating them with a “|”
/path/to/my/spash.jpg|/path/to/my/media.flv,300,150
This will be rolled into the next update, as soon as I can get some time to actually work on it!!
EDIT: despite the date of this post, no it’s not a joke
Tags: flowplayer, patch
2 Comments »
Posted by: Buzz in Linux
Following on from the python bindings post I found myself with a real problem,
the netsnmp bindings I could not for the life of me get to take the redhat cluste MIB files, so what did that leave me with, walking the entire parent cluster OID, manually matching the returned OID’s to their MIB names based on the value returned as I couldn’t find a decent mib browser or script to convert them …
At any rate here is a subset of OID’s for polling the redhat cluster service using snmp, please note that are more OID’s but these vary on your cluster config.
Python code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| rhc_oid = '.1.3.6.1.4.1.2312.8'
data_oids = {
'rhcMIBVersion':'.1.1',
'rhcClusterName':'.2.1',
'rhcClusterStatusCode':'.2.2',
'rhcClusterStatusDesc':'.2.3',
'rhcClusterVotesNeededForQuorum':'.2.4',
'rhcClusterVotes':'.2.5',
'rhcClusterQuorate':'.2.6',
'rhcClusterNodesNum':'.2.7',
'rhcClusterNodesNames':'.2.8',
'rhcClusterAvailNodesNum':'.2.9',
'rhcClusterAvailNodesNames':'.2.10',
'rhcClusterUnavailNodesNum':'.2.11',
'rhcClusterUnavailNodesNames':'.2.12',
'rhcClusterServicesNum':'.2.13',
'rhcClusterServicesNames':'.2.14',
'rhcClusterRunningServicesNum':'.2.15',
'rhcClusterRunningServicesNames':'.2.16',
'rhcClusterStoppedServicesNum':'.2.17',
'rhcClusterStoppedServicesNames':'.2.18',
'rhcClusterFailedServicesNum':'.2.19',
'rhcClusterFailedServicesNames':'.2.20'}
for item in data_oids:
oid = '%s%s' % (rhc_oid,data_oids[item])
print item,oid |
Tags: oid, python, redhat, snmp
No Comments »
Posted by: Buzz in python
UPDATE 28/06/10: added –libdir=/usr/lib64 –enable-shared otherwise shared libs are not built at all!
Having spent a few hours trying to get this working on CentOS 5.4 x64 I am posting this blog entry for others to reference:
Download and complie net-snmp >= 5.4.2.1 http://net-snmp.sourceforge.net/
1 2 3 4 5
| ./configure --with-python-modules --libdir=/usr/lib64 --enable-shared
make && make install
cd /path/to/net-snmp-src/python/
python ./setup.py build
python ./setup.py test |
You may get ImportError: libnetsnmp.so.20, this is due to x64 build creating as /usr/lib64/libnetsnmp.so.10
1 2
| ln -s /usr/lib64/libnetsnmp.so.10.0.3 /usr/lib64/libnetsnmp.so.20
python ./setup.py install |
And you are done, you can now use the netsnmp python bindings, I’d recomend seeing the examples here: http://www.ibm.com/developerworks/aix/library/au-netsnmpnipython/
Tags: bindings, net-snmp, python, snmp
No Comments »
|