home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / exploits / lockdexvul / 0x333-lockdexvul.txt
Encoding:
Text File  |  2003-08-20  |  9.5 KB  |  278 lines

  1.            -       0x333 OUTSIDERS SECURITY LABS       -
  2.             -              www.0x333.org              -
  3.  
  4.          lockdev in redhat 7.3 ,8.0 ,9.0 possible all linux os has Segmentation fault
  5.  
  6. ~~~ contents ~~~
  7.  
  8. [0x0] Info
  9. [0x1] Description
  10. [0x2] Vulnerable code
  11. [0x3] Debug session
  12. [0x4] Exploit
  13.  
  14.  
  15. [0x0] Info
  16. Author      : nic
  17. Email       : nic0x333@hotmail.com
  18. Date        : 28 July 2003
  19. Advisory    : outsiders-004.txt
  20. Vender URL  : http://www.hklpg.org/RPM/rawhide/1.0/ia64/RedHat/RPMS/lockdev-1.0.0-21.ia64.html
  21. Category    : vul  bug 
  22. OS affected : redhat 7.3 8.0 possible 9.0 --> all redhat  
  23.  
  24. [0x1] Description
  25.  
  26. lockdev is defaultly installed  in all redhat os, or other linux os. our team find a bug.
  27.  
  28. it is affected by a vul bug.  it is +s lock group. The  exploit will spawn a shell with 
  29.  
  30. gid=xx(lock).
  31.  
  32.  
  33.  
  34. [0x2] Vulnerable code
  35.  
  36. In setup.c we found :
  37.  
  38. /*
  39.  * local function list_setups
  40.  */
  41.  
  42. /* exported by the interface file lockdev.h */
  43.  
  44. main()
  45.  
  46. case 'u':
  47.   i = dev_unlock( dev, 0);
  48.   break;
  49. .............................
  50.  
  51.  
  52.  
  53. /* exported by the interface file lockdev.h */
  54. pid_t
  55. dev_unlock( devname, pid)
  56.     const char * devname;
  57.     const pid_t pid;
  58. {
  59.     const char * p;
  60.     char device[MAXPATHLEN+1];
  61.     char lock0[MAXPATHLEN+1];
  62.     char lock1[MAXPATHLEN+1];
  63.     char lock2[MAXPATHLEN+1];
  64.     struct stat statbuf;
  65.     pid_t wpid;
  66.  
  67. #if DEBUG
  68.     if ( env_var_debug == -1 ) {
  69.         char *value;
  70.         if ( value=getenv( _env_var ) )
  71.             env_var_debug = liblockdev_debug = atoi( value);
  72.         signal( SIGUSR1, _dl_sig_handler);
  73.         signal( SIGUSR2, _dl_sig_handler);
  74.     }
  75. #endif /* DEBUG */
  76.     _debug( 3, "dev_unlock(%s, %d)\n", devname, (int)pid);
  77.     if (oldmask == -1 )
  78.         oldmask = umask( 0);    /* give full permissions to files created */
  79.     if ( ! (p=_dl_check_devname( devname)) )
  80.          close_n_return( -1);
  81.     strcpy( device, DEV_PATH);
  82.     strcat( device, p);    /* now device has a copy of the pathname */
  83.     _debug( 2, "dev_unlock() device = %s\n", device);
  84.  
  85.     /* check the device name for existence and retrieve the major
  86.      * and minor numbersn
  87.     if ( stat( device, &statbuf) == -1 ) {
  88.         close_n_return( -1);
  89.     }
  90.  
  91.     /* first remove the FSSTND-1.2 lock, get the pid of the
  92.      * owner of the lock and test for its existence; in case,
  93.      * return the pid of the owner of the lock.
  94.      */
  95.     /* lockfile of type /var/lock/LCK..ttyS2 */
  96.     _dl_filename_2( lock2, p);
  97.     wpid = _dl_check_lock( lock2);
  98.     if ( pid && wpid && pid != wpid )
  99.         close_n_return( wpid);    /* error or locked by someone else */
  100.  
  101.     /* lockfile of type /var/lock/LCK.004.064 */
  102.     _dl_filename_1( lock1, &statbuf);
  103.     wpid = _dl_check_lock( lock1);
  104.     if ( pid && wpid && pid != wpid )
  105.         close_n_return( wpid);    /* error or locked by someone else */
  106.  
  107.     _dl_filename_0( lock0, wpid);
  108.     if ( wpid == _dl_check_lock( lock0))
  109.         unlink( lock0);
  110.  
  111.     /* anyway now we remove the files, in the reversed order than
  112.      * they have been built.
  113.      */
  114.     unlink( lock2);
  115.     unlink( lock1);
  116.     _debug( 2, "dev_unlock() unlocked\n");
  117.     close_n_return( 0);    /* successfully unlocked */
  118. }
  119.  
  120. ..........................................................................
  121.  
  122.  
  123. _dl_check_devname( devname)
  124.     const char * devname;
  125. {
  126.     int l;
  127.     const char * p;
  128.     char *m;
  129.  
  130.     /* devname can be absolute, relative to PWD or a single
  131.      * filename, in any case we assume that the file is in /dev;
  132.      * maybe we should check it and do something if not?
  133.      */
  134.     p = devname;    /* only a filename */
  135.     while ( (m=strrchr( p, '/')) != 0 ) {                     ....................pointer
  136.         p = m+1;    /* was pointing to the slash */
  137. .....................................................................................
  138. [0x3] Debug session
  139.  
  140. bash-2.05a$ gdb ./lockdev
  141. GNU gdb Red Hat Linux (5.1.90CVS-5)
  142. Copyright 2002 Free Software Foundation, Inc.
  143. GDB is free software, covered by the GNU General Public License, and you are
  144. welcome to change it and/or distribute copies of it under certain conditions.
  145. Type "show copying" to see the conditions.
  146. There is absolutely no warranty for GDB.  Type "show warranty" for details.
  147. This GDB was configured as "i386-redhat-linux"...
  148. (no debugging symbols found)...
  149. (gdb) r -u
  150. Starting program: /usr/sbin/lockdev -u
  151. (no debugging symbols found)...(no debugging symbols found)...
  152. Program received signal SIGSEGV, Segmentation fault.
  153. 0x42080f33 in strrchr () from /lib/i686/libc.so.6
  154. (gdb) disas dev_unlock
  155. Dump of assembler code for function dev_unlock:
  156. 0x8049b80 <dev_unlock>: push   %ebp
  157. 0x8049b81 <dev_unlock+1>:       mov    %esp,%ebp
  158. 0x8049b83 <dev_unlock+3>:       push   %edi
  159. 0x8049b84 <dev_unlock+4>:       push   %esi
  160. 0x8049b85 <dev_unlock+5>:       push   %ebx
  161. 0x8049b86 <dev_unlock+6>:       sub    $0x407c,%esp
  162. 0x8049b8c <dev_unlock+12>:      call   0x8048d10 <main+528>
  163. 0x8049b91 <dev_unlock+17>:      add    $0x56f,%ebx
  164. 0x8049b97 <dev_unlock+23>:      cmpl   $0xffffffff,0xffffff1c(%ebx)
  165. 0x8049b9e <dev_unlock+30>:      jne    0x8049bb3 <dev_unlock+51>
  166. 0x8049ba0 <dev_unlock+32>:      sub    $0xc,%esp
  167. 0x8049ba3 <dev_unlock+35>:      push   $0x2
  168. 0x8049ba5 <dev_unlock+37>:      call   0x804882c <umask>
  169. 0x8049baa <dev_unlock+42>:      mov    %eax,0xffffff1c(%ebx)
  170. 0x8049bb0 <dev_unlock+48>:      add    $0x10,%esp
  171. 0x8049bb3 <dev_unlock+51>:      mov    0x8(%ebp),%eax
  172. 0x8049bb6 <dev_unlock+54>:      sub    $0xc,%esp
  173. 0x8049bb9 <dev_unlock+57>:      push   %eax
  174. 0x8049bba <dev_unlock+58>:      call   0x8049110 <_dl_check_devname>
  175. 0x8049bbf <dev_unlock+63>:      mov    %eax,%edi
  176. 0x8049bc1 <dev_unlock+65>:      add    $0x10,%esp
  177. 0x8049bc4 <dev_unlock+68>:      test   %edi,%edi
  178. ---Type <return> to continue, or q <return> to quit---q
  179. Quit
  180. (gdb) b *0x8049bba
  181. Breakpoint 1 at 0x8049bba
  182. (gdb) r -u
  183. The program being debugged has been started already.
  184. Start it from the beginning? (y or n) y
  185. Starting program: /usr/sbin/lockdev -u
  186. (no debugging symbols found)...(no debugging symbols found)...
  187. Breakpoint 1, 0x08049bba in dev_unlock ()
  188. (gdb) b *0x8049bbf
  189. Breakpoint 2 at 0x8049bbf
  190. (gdb) r
  191. The program being debugged has been started already.
  192. Start it from the beginning? (y or n) y
  193. Starting program: /usr/sbin/lockdev -u
  194. (no debugging symbols found)...(no debugging symbols found)...
  195. Breakpoint 1, 0x08049bba in dev_unlock ()
  196. (gdb) c
  197. Continuing.
  198.  
  199. Program received signal SIGSEGV, Segmentation fault.
  200. 0x42080f33 in strrchr () from /lib/i686/libc.so.6
  201. (gdb)
  202.  
  203. so i can deside  bug is in  <0x8049bbf <dev_unlock+63>:      mov    %eax,%edi>
  204. (gdb) disas strrchr
  205. Dump of assembler code for function strrchr:
  206. 0x42080e90 <strrchr>:   push   %edi
  207. 0x42080e91 <strrchr+1>: push   %esi
  208. 0x42080e92 <strrchr+2>: xor    %eax,%eax
  209. 0x42080e94 <strrchr+4>: mov    0xc(%esp,1),%esi
  210. 0x42080e98 <strrchr+8>: mov    0x10(%esp,1),%ecx
  211. 0x42080e9c <strrchr+12>:        mov    %cl,%ch
  212. 0x42080e9e <strrchr+14>:        mov    %ecx,%edx
  213. 0x42080ea0 <strrchr+16>:        shl    $0x10,%ecx
  214. 0x42080ea3 <strrchr+19>:        mov    %dx,%cx
  215. 0x42080ea6 <strrchr+22>:        test   $0x3,%esi
  216. 0x42080eac <strrchr+28>:        je     0x42080f33 <strrchr+163>
  217. 0x42080eb2 <strrchr+34>:        mov    (%esi),%dl
  218. 0x42080eb4 <strrchr+36>:        cmp    %dl,%cl
  219. 0x42080eb6 <strrchr+38>:        jne    0x42080eba <strrchr+42>
  220. 0x42080eb8 <strrchr+40>:        mov    %esi,%eax
  221. 0x42080eba <strrchr+42>:        or     %dl,%dl
  222. 0x42080ebc <strrchr+44>:        je     0x42081046 <strrchr+438>
  223. 0x42080ec2 <strrchr+50>:        inc    %esi
  224. 0x42080ec3 <strrchr+51>:        test   $0x3,%esi
  225. 0x42080ec9 <strrchr+57>:        je     0x42080f33 <strrchr+163>
  226. 0x42080ecb <strrchr+59>:        mov    (%esi),%dl
  227. 0x42080ecd <strrchr+61>:        cmp    %dl,%cl
  228. ---Type <return> to continue, or q <return> to quit---
  229. 0x42080ecf <strrchr+63>:        jne    0x42080ed3 <strrchr+67>
  230. 0x42080ed1 <strrchr+65>:        mov    %esi,%eax
  231. 0x42080ed3 <strrchr+67>:        or     %dl,%dl
  232. 0x42080ed5 <strrchr+69>:        je     0x42081046 <strrchr+438>
  233. 0x42080edb <strrchr+75>:        inc    %esi
  234. 0x42080edc <strrchr+76>:        test   $0x3,%esi
  235. 0x42080ee2 <strrchr+82>:        je     0x42080f33 <strrchr+163>
  236. 0x42080ee4 <strrchr+84>:        mov    (%esi),%dl
  237. 0x42080ee6 <strrchr+86>:        cmp    %dl,%cl
  238. 0x42080ee8 <strrchr+88>:        jne    0x42080eec <strrchr+92>
  239. 0x42080eea <strrchr+90>:        mov    %esi,%eax
  240. 0x42080eec <strrchr+92>:        or     %dl,%dl
  241. 0x42080eee <strrchr+94>:        je     0x42081046 <strrchr+438>
  242. 0x42080ef4 <strrchr+100>:       inc    %esi
  243. 0x42080ef5 <strrchr+101>:       jmp    0x42080f33 <strrchr+163>
  244. 0x42080ef7 <strrchr+103>:       add    %al,(%eax)
  245. 0x42080ef9 <strrchr+105>:       add    %al,0xee8304ee(%ebx)
  246. 0x42080eff <strrchr+111>:       add    $0x83,%al
  247. 0x42080f01 <strrchr+113>:       out    %al,(%dx)
  248. 0x42080f02 <strrchr+114>:       add    $0xf7,%al
  249. 0x42080f04 <strrchr+116>:       ret    $0x0
  250. 0x42080f07 <strrchr+119>:       add    %bh,%bh
  251. 0x42080f09 <strrchr+121>:       jne    0x42080f19 <strrchr+137>
  252. ---Type <return> to continue, or q <return> to quit---
  253. 0x42080f0b <strrchr+123>:       lea    0xf(%esi),%eax
  254. 0x42080f0e <strrchr+126>:       jmp    0x42080f30 <strrchr+160>
  255. 0x42080f10 <strrchr+128>:       sub    $0x4,%esi
  256. 0x42080f13 <strrchr+131>:       sub    $0x4,%esi
  257. 0x42080f16 <strrchr+134>:       sub    $0x4,%esi
  258. 0x42080f19 <strrchr+137>:       test   $0xff0000,%edx
  259. 0x42080f1f <strrchr+143>:       jne    0x42080f26 <strrchr+150>
  260. 0x42080f21 <strrchr+145>:       lea    0xe(%esi),%eax
  261. 0x42080f24 <strrchr+148>:       jmp    0x42080f30 <strrchr+160>
  262. 0x42080f26 <strrchr+150>:       lea    0xc(%esi),%eax
  263. 0x42080f29 <strrchr+153>:       test   %dh,%dh
  264. 0x42080f2b <strrchr+155>:       jne    0x42080f30 <strrchr+160>
  265. 0x42080f2d <strrchr+157>:       lea    0xd(%esi),%eax
  266. 0x42080f30 <strrchr+160>:       add    $0x10,%esi
  267. 0x42080f33 <strrchr+163>:       mov    (%esi),%edx
  268. (gdb)
  269.  
  270.  
  271. .......................................
  272.  
  273.  
  274. [0x4] Exploit
  275. ....
  276.  
  277. EOF
  278.