-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the Instance class dict compatible to allow for JSON serialization.
- Loading branch information
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
from dissect.cstruct import cstruct, dumpstruct | ||
|
||
import json | ||
import socket | ||
import struct | ||
|
||
class CustomEncoder(json.JSONEncoder): | ||
def default(self, obj): | ||
if isinstance(obj, bytes): | ||
return obj.decode('utf-8', errors='surrogateescape') | ||
return json.JSONEncoder.default(self, obj) | ||
|
||
protocol = cstruct() | ||
|
||
protocol.load( | ||
""" | ||
enum AttackType : uint8 { | ||
ATK_OPT_DPORT = 7, | ||
ATK_OPT_DOMAIN = 8, | ||
ATK_OPT_NUM_SOCKETS = 24, | ||
}; | ||
struct AttackTarget { | ||
DWORD ipv4; | ||
BYTE netmask; | ||
}; | ||
struct AttackOption { | ||
AttackType type; | ||
uint8 value_length; | ||
char value[value_length]; | ||
}; | ||
struct MiraiAttack { | ||
uint16 total_length; | ||
uint32 duration; | ||
uint8 attack_id; | ||
uint8 target_count; | ||
AttackTarget targets[target_count]; | ||
uint8 num_opts; | ||
AttackOption attack_options[num_opts]; | ||
}; | ||
""" | ||
) | ||
|
||
protocol.endian = ">" | ||
|
||
if __name__ == "__main__": | ||
data = b"\x000\x00\x00\x00d\n\x01\x08\x08\x08\x08 \x03\x08\x16http://www.example.com\x07\x0280\x18\x045000" | ||
|
||
record = protocol.MiraiAttack(data) | ||
print(json.dumps(record, cls=CustomEncoder)) |