Benutzer-Werkzeuge

Webseiten-Werkzeuge


metasploit

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
metasploit [2025/11/14 22:04]
admin
metasploit [2025/11/14 22:42] (aktuell)
admin [Sonstige]
Zeile 30: Zeile 30:
 =====Ein Modul schreiben===== =====Ein Modul schreiben=====
  
 +Eine Ruby Datei unter
 +
 +<code>
 +.msf4/modules/<type>/<name>
 +</code>
 +
 +Danach 
 +
 +<code>
 +reload_all
 +</code>
 ====Auxiliary==== ====Auxiliary====
  
 Server Version aus Header abfragen Server Version aus Header abfragen
 +
 +<code bash>
 +nano .msf4/modules/auxiliary/scanner/webserver_version.rb
 +</code>
 +
 <code ruby> <code ruby>
 require 'msf/core' require 'msf/core'
Zeile 80: Zeile 96:
 </code> </code>
  
 +<code>
 +msfconsole
 +reload_all
 +search webserver_version
 +use auxiliary/scanner/webserver_version
 +</code>
 +
 +====Exploit====
 +
 +<code ruby>
 +# safe_demo_exploit.rb
 +# Harmloses Demo-Exploitmodul zum Lernen
 +
 +require 'msf/core'
 +
 +class MetasploitModule < Msf::Exploit::Remote
 +  Rank = NormalRanking
 +
 +  # Wir benutzen eine einfache TCP-Verbindung
 +  include Msf::Exploit::Remote::Tcp
 +
 +  def initialize(info = {})
 +    super(update_info(info,
 +      'Name'           => 'Safe Demo Exploit (Lernmodul)',
 +      'Description'    => %q{
 +        Dieses Modul demonstriert die Struktur eines Exploit-Moduls.
 +        Es verbindet sich nur mit einem TCP-Dienst, schickt eine Testnachricht
 +        und meldet "Erfolg", ohne irgendetwas auszunutzen.
 +      },
 +      'Author'         => ['mbrain'],
 +      'License'        => MSF_LICENSE,
 +      'DisclosureDate' => 'Jan 01 2025',
 +      'Platform'       => 'unix',
 +      'Targets'        =>
 +        [
 +          [
 +            'Demo Target',
 +            {
 +              'Platform' => 'unix'
 +            }
 +          ]
 +        ],
 +      'DefaultTarget'  => 0,
 +      # Wir brauchen keinen richtigen Payload, also minimale Config
 +      'Payload'        =>
 +        {
 +          'Space'       => 0,
 +          'DisableNops' => true
 +        }
 +    ))
 +
 +    register_options(
 +      [
 +        Opt::RHOSTS(nil),
 +        Opt::RPORT(80),
 +        OptString.new('DEMO_STRING', [ true, 'String, der an den Server gesendet wird', "HELLO FROM METASPLOIT\r\n" ])
 +      ]
 +    )
 +  end
 +
 +  # "check" simuliert nur, dass der Dienst "verwundbar" aussieht
 +  def check
 +    vprint_status("Versuche Verbindung zu #{rhost}:#{rport} für Demo-Check...")
 +    begin
 +      connect
 +      print_good("Verbindung hat geklappt – wir tun mal so, als wäre der Dienst verwundbar.")
 +      disconnect
 +      return CheckCode::Appears
 +    rescue ::Rex::ConnectionError
 +      print_error("Keine Verbindung möglich.")
 +      return CheckCode::Unknown
 +    end
 +  end
 +
 +  # "exploit" wird aufgerufen, wenn du "run" bzw. "exploit" eingibst
 +  def exploit
 +    print_status("Starte Demo-Exploit gegen #{rhost}:#{rport} ...")
 +
 +    begin
 +      connect
 +      print_status("Sende Demo-String an den Server...")
 +      sock.put(datastore['DEMO_STRING'])
 +
 +      # Versuche eine Antwort zu lesen (falls vorhanden)
 +      res = sock.get_once(1024, 3)
 +
 +      if res
 +        print_good("Server hat geantwortet:")
 +        print_line(res)
 +      else
 +        print_warning("Keine Antwort erhalten (aber das ist für die Demo ok).")
 +      end
 +
 +      print_good("Demo-Exploit erfolgreich ausgeführt (keine echte Ausnutzung).")
 +    rescue ::Rex::ConnectionError
 +      print_error("Verbindung fehlgeschlagen.")
 +    ensure
 +      disconnect
 +    end
 +  end
 +end
 +</code>
 ====Sonstige==== ====Sonstige====
  
Zeile 121: Zeile 239:
       {       {
         'RPORT' => 80,         'RPORT' => 80,
-        'RHOSTS' => '192.168.0.157'+        'RHOSTS' => '192.168.0.157', 
 +        'URI' => '/'
       },       },
       'DefaultTarget'  => 0))       'DefaultTarget'  => 0))
Zeile 224: Zeile 343:
 </code> </code>
  
 +<code ruby>
 +require 'msf/core'
  
 +class MetasploitModule < Msf::Auxiliary
 +  include Msf::Exploit::Remote::HttpClient
 +
 +  def initialize(info = {})
 +    super(update_info(info,
 +      'Name'        => 'Test URL Fetcher',
 +      'Description' => %q{
 +        Dieses Modul ruft eine beliebige URI von einem HTTP-Server ab.
 +        Nützlich zum Lernen, Testen und Debuggen eigener Module.
 +      },
 +      'Author'      => ['mbrain'],
 +      'License'     => MSF_LICENSE
 +    ))
 +
 +    register_options(
 +      [
 +        Opt::RHOSTS(nil),
 +        Opt::RPORT(80),
 +        OptString.new('URI', [ true, 'Pfad/URL, die abgerufen werden soll', '/' ])
 +      ]
 +    )
 +  end
 +
 +  def run
 +    print_status("Rufe http://#{rhost}:#{rport}#{datastore['URI']} ab...")
 +
 +    begin
 +      res = send_request_cgi({
 +        'method' => 'GET',
 +        'uri'    => datastore['URI']
 +      })
 +
 +      if res
 +        print_good("Status: #{res.code}")
 +        print_good("Server-Header: #{res.headers['Server']}") if res.headers['Server']
 +
 +        print_line("")
 +        print_line("=== Inhalt der Antwort ===")
 +        print_line(res.body || "<kein Inhalt>")
 +      else
 +        print_error("Keine Antwort erhalten.")
 +      end
 +
 +    rescue ::Rex::ConnectionError
 +      print_error("Verbindung fehlgeschlagen")
 +    end
 +  end
 +end
 +</code>
 +
 +
 +<code ruby>
 +# MySampleModule
 + 
 +class MetasploitModule < Msf::Exploit::Remote
 +  Rank = NormalRanking
 + 
 +  include Msf::Exploit::Remote::Tcp
 + 
 +  def initialize(info = {})
 +    super(update_info(info,
 +      'Name'           => 'My sample Exploit',
 +      'Description'    => %q{
 +        This file illustrates how to write a module.
 +      },
 +      'License'        => 'UnLicense',
 +      'Author'         => ['mbrain'],
 +      'References'     =>
 +        [
 +          [ 'CVE', '1234-5678' ],
 +        ],
 +      'Payload'        =>
 +        {
 +          'Space'    => 1000,
 +          'BadChars' => "\x00",
 +        },
 +      'Targets'        =>
 +        [
 +          [
 +            'Windows XP/Vista/7/8',
 +            {
 +              'Platform' => 'win',
 +              'Ret'      => 0x41424344
 +            }
 +          ],
 +        ],
 +      'DisclosureDate' => 'Apr 1 2013',
 +      'DefaultOptions' =>
 +        {
 +          'RPORT'  => 80,
 +          'RHOSTS' => '192.168.0.157'
 +        },
 +      'DefaultTarget'  => 0
 +    ))
 + 
 +    register_options(
 +      [
 +        Opt::RPORT(4444) # Beispieloption für den Remote-Port
 +      ]
 +    )
 +  end
 + 
 +  # Usually this includes code for checking
 +  def check
 +    CheckCode::Vulnerable
 +  end
 + 
 +def exploit
 +  print_status("Baue TCP-Verbindung zu #{rhost}:#{rport} auf...")
 +  connect
 +
 +  uri = '/'
 +  print_status("Sende langsamen HTTP GET Request an #{rhost}:#{rport}#{uri} ...")
 +
 +  # 1) Request-Line
 +  sock.put("GET #{uri} HTTP/1.1\r\n")
 +  sleep(1)  # 1 Sekunde Pause – nur Demo
 +
 +  # 2) Host-Header
 +  sock.put("Host: #{rhost}\r\n")
 +  sleep(1)
 +
 +  # 3) User-Agent
 +  sock.put("User-Agent: SlowDemoMetasploit\r\n")
 +  sleep(1)
 +
 +  # 4) Connection-Header
 +  sock.put("Connection: close\r\n")
 +  sleep(1)
 +
 +  # 5) Leere Zeile zum Abschließen des Headers
 +  sock.put("\r\n")
 +
 +  print_status("Request komplett geschickt, warte auf Antwort...")
 +
 +  # Antwort lesen (einmalig)
 +  response = sock.get_once(-1, 5)  # bis zu 5 Sekunden warten
 +
 +  if response
 +    print_good("Antwort erhalten:")
 +    print_line(response)
 +  else
 +    print_warning("Keine Antwort erhalten (Timeout).")
 +  end
 +
 +  disconnect
 +end
 +end
 +</code>
 =====Links===== =====Links=====
  
metasploit.1763154269.txt.gz · Zuletzt geändert: 2025/11/14 22:04 von admin