Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
|
metasploit [2025/11/14 21:59] admin [Ein Modul schreiben] |
metasploit [2025/11/14 22:42] (aktuell) admin [Sonstige] |
||
|---|---|---|---|
| Zeile 29: | Zeile 29: | ||
| =====Ein Modul schreiben===== | =====Ein Modul schreiben===== | ||
| + | |||
| + | Eine Ruby Datei unter | ||
| + | |||
| + | < | ||
| + | .msf4/ | ||
| + | </ | ||
| + | |||
| + | Danach | ||
| + | |||
| + | < | ||
| + | reload_all | ||
| + | </ | ||
| + | ====Auxiliary==== | ||
| + | |||
| + | Server Version aus Header abfragen | ||
| + | |||
| + | <code bash> | ||
| + | nano .msf4/ | ||
| + | </ | ||
| + | |||
| + | <code ruby> | ||
| + | require ' | ||
| + | |||
| + | class MetasploitModule < Msf:: | ||
| + | include Msf:: | ||
| + | |||
| + | def initialize(info = {}) | ||
| + | super(update_info(info, | ||
| + | ' | ||
| + | ' | ||
| + | Dieses Modul führt eine einfache HTTP-Anfrage aus und zeigt die Server-Version. | ||
| + | Es ist ein ungefährliches Beispielmodul zum Lernen. | ||
| + | }, | ||
| + | ' | ||
| + | ' | ||
| + | )) | ||
| + | |||
| + | register_options( | ||
| + | [ | ||
| + | Opt:: | ||
| + | Opt:: | ||
| + | ] | ||
| + | ) | ||
| + | end | ||
| + | |||
| + | def run | ||
| + | print_status(" | ||
| + | |||
| + | begin | ||
| + | res = send_request_cgi({ | ||
| + | ' | ||
| + | ' | ||
| + | }) | ||
| + | |||
| + | if res && res.headers[' | ||
| + | print_good(" | ||
| + | else | ||
| + | print_warning(" | ||
| + | end | ||
| + | |||
| + | rescue :: | ||
| + | print_error(" | ||
| + | end | ||
| + | end | ||
| + | end | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | msfconsole | ||
| + | reload_all | ||
| + | search webserver_version | ||
| + | use auxiliary/ | ||
| + | </ | ||
| + | |||
| + | ====Exploit==== | ||
| + | |||
| + | <code ruby> | ||
| + | # safe_demo_exploit.rb | ||
| + | # Harmloses Demo-Exploitmodul zum Lernen | ||
| + | |||
| + | require ' | ||
| + | |||
| + | class MetasploitModule < Msf:: | ||
| + | Rank = NormalRanking | ||
| + | |||
| + | # Wir benutzen eine einfache TCP-Verbindung | ||
| + | include Msf:: | ||
| + | |||
| + | def initialize(info = {}) | ||
| + | super(update_info(info, | ||
| + | ' | ||
| + | ' | ||
| + | Dieses Modul demonstriert die Struktur eines Exploit-Moduls. | ||
| + | Es verbindet sich nur mit einem TCP-Dienst, schickt eine Testnachricht | ||
| + | und meldet " | ||
| + | }, | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | [ | ||
| + | [ | ||
| + | 'Demo Target', | ||
| + | { | ||
| + | ' | ||
| + | } | ||
| + | ] | ||
| + | ], | ||
| + | ' | ||
| + | # Wir brauchen keinen richtigen Payload, also minimale Config | ||
| + | ' | ||
| + | { | ||
| + | ' | ||
| + | ' | ||
| + | } | ||
| + | )) | ||
| + | |||
| + | register_options( | ||
| + | [ | ||
| + | Opt:: | ||
| + | Opt:: | ||
| + | OptString.new(' | ||
| + | ] | ||
| + | ) | ||
| + | end | ||
| + | |||
| + | # " | ||
| + | def check | ||
| + | vprint_status(" | ||
| + | begin | ||
| + | connect | ||
| + | print_good(" | ||
| + | disconnect | ||
| + | return CheckCode:: | ||
| + | rescue :: | ||
| + | print_error(" | ||
| + | return CheckCode:: | ||
| + | end | ||
| + | end | ||
| + | |||
| + | # " | ||
| + | def exploit | ||
| + | print_status(" | ||
| + | |||
| + | begin | ||
| + | connect | ||
| + | print_status(" | ||
| + | sock.put(datastore[' | ||
| + | |||
| + | # Versuche eine Antwort zu lesen (falls vorhanden) | ||
| + | res = sock.get_once(1024, | ||
| + | |||
| + | if res | ||
| + | print_good(" | ||
| + | print_line(res) | ||
| + | else | ||
| + | print_warning(" | ||
| + | end | ||
| + | |||
| + | print_good(" | ||
| + | rescue :: | ||
| + | print_error(" | ||
| + | ensure | ||
| + | disconnect | ||
| + | end | ||
| + | end | ||
| + | end | ||
| + | </ | ||
| + | ====Sonstige==== | ||
| <code ruby> | <code ruby> | ||
| Zeile 69: | Zeile 239: | ||
| { | { | ||
| ' | ' | ||
| - | ' | + | ' |
| + | ' | ||
| }, | }, | ||
| ' | ' | ||
| Zeile 172: | Zeile 343: | ||
| </ | </ | ||
| - | Auxiliary | ||
| <code ruby> | <code ruby> | ||
| require ' | require ' | ||
| Zeile 181: | Zeile 351: | ||
| def initialize(info = {}) | def initialize(info = {}) | ||
| super(update_info(info, | super(update_info(info, | ||
| - | ' | + | ' |
| ' | ' | ||
| - | Dieses Modul führt | + | Dieses Modul ruft eine beliebige URI von einem HTTP-Server |
| - | | + | |
| }, | }, | ||
| ' | ' | ||
| Zeile 193: | Zeile 363: | ||
| [ | [ | ||
| Opt:: | Opt:: | ||
| - | Opt:: | + | Opt:: |
| + | OptString.new(' | ||
| ] | ] | ||
| ) | ) | ||
| Zeile 199: | Zeile 370: | ||
| def run | def run | ||
| - | print_status(" | + | print_status(" |
| begin | begin | ||
| res = send_request_cgi({ | res = send_request_cgi({ | ||
| ' | ' | ||
| - | ' | + | ' |
| }) | }) | ||
| - | if res && | + | if res |
| - | print_good(" | + | print_good(" |
| + | print_good(" | ||
| + | |||
| + | print_line("" | ||
| + | print_line(" | ||
| + | print_line(res.body || "< | ||
| else | else | ||
| - | | + | |
| end | end | ||
| Zeile 220: | Zeile 396: | ||
| </ | </ | ||
| + | |||
| + | <code ruby> | ||
| + | # MySampleModule | ||
| + | |||
| + | class MetasploitModule < Msf:: | ||
| + | Rank = NormalRanking | ||
| + | |||
| + | include Msf:: | ||
| + | |||
| + | def initialize(info = {}) | ||
| + | super(update_info(info, | ||
| + | ' | ||
| + | ' | ||
| + | This file illustrates how to write a module. | ||
| + | }, | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | [ | ||
| + | [ ' | ||
| + | ], | ||
| + | ' | ||
| + | { | ||
| + | ' | ||
| + | ' | ||
| + | }, | ||
| + | ' | ||
| + | [ | ||
| + | [ | ||
| + | ' | ||
| + | { | ||
| + | ' | ||
| + | ' | ||
| + | } | ||
| + | ], | ||
| + | ], | ||
| + | ' | ||
| + | ' | ||
| + | { | ||
| + | ' | ||
| + | ' | ||
| + | }, | ||
| + | ' | ||
| + | )) | ||
| + | |||
| + | register_options( | ||
| + | [ | ||
| + | Opt:: | ||
| + | ] | ||
| + | ) | ||
| + | end | ||
| + | |||
| + | # Usually this includes code for checking | ||
| + | def check | ||
| + | CheckCode:: | ||
| + | end | ||
| + | |||
| + | def exploit | ||
| + | print_status(" | ||
| + | connect | ||
| + | |||
| + | uri = '/' | ||
| + | print_status(" | ||
| + | |||
| + | # 1) Request-Line | ||
| + | sock.put(" | ||
| + | sleep(1) | ||
| + | |||
| + | # 2) Host-Header | ||
| + | sock.put(" | ||
| + | sleep(1) | ||
| + | |||
| + | # 3) User-Agent | ||
| + | sock.put(" | ||
| + | sleep(1) | ||
| + | |||
| + | # 4) Connection-Header | ||
| + | sock.put(" | ||
| + | sleep(1) | ||
| + | |||
| + | # 5) Leere Zeile zum Abschließen des Headers | ||
| + | sock.put(" | ||
| + | |||
| + | print_status(" | ||
| + | |||
| + | # Antwort lesen (einmalig) | ||
| + | response = sock.get_once(-1, | ||
| + | |||
| + | if response | ||
| + | print_good(" | ||
| + | print_line(response) | ||
| + | else | ||
| + | print_warning(" | ||
| + | end | ||
| + | |||
| + | disconnect | ||
| + | end | ||
| + | end | ||
| + | </ | ||
| =====Links===== | =====Links===== | ||