|
| 1 | +package general |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "strings" |
| 6 | + |
| 7 | + methodwebtest "github.com/Method-Security/methodwebtest/generated/go" |
| 8 | + utils "github.com/Method-Security/methodwebtest/utils/engines" |
| 9 | +) |
| 10 | + |
| 11 | +var SSTIPayloads = []string{ |
| 12 | + "${1337*42}", |
| 13 | + "{{1337*42}}", |
| 14 | + "<%= 1337 * 42 %>", |
| 15 | + "#{ 1337 * 42 }", |
| 16 | + "${{1337*42}}", |
| 17 | +} |
| 18 | + |
| 19 | +func PerformSSTIReflectInjection(ctx context.Context, config *methodwebtest.MultiInjectionConfig) *methodwebtest.Report { |
| 20 | + generatedPayloads := utils.GenerateInjectionPayloads(SSTIPayloads, config.VariableData) |
| 21 | + |
| 22 | + injectionConfig := methodwebtest.InjectionEngineConfig{ |
| 23 | + Targets: config.Targets, |
| 24 | + Method: config.Method, |
| 25 | + Paths: []string{"/"}, |
| 26 | + InjectedPayloads: generatedPayloads, |
| 27 | + InjectionLocation: config.InjectionLocation, |
| 28 | + EventType: methodwebtest.NewEventTypeFromMultiEvent(methodwebtest.MultiEventSstireflect), |
| 29 | + FollowRedirects: true, |
| 30 | + Timeout: config.Timeout, |
| 31 | + Retries: config.Retries, |
| 32 | + Sleep: config.Sleep, |
| 33 | + } |
| 34 | + |
| 35 | + report := utils.RunMultiInjectionsEngine(ctx, &injectionConfig) |
| 36 | + checkForSSTIReflect(report) |
| 37 | + return report |
| 38 | +} |
| 39 | + |
| 40 | +func checkForSSTIReflect(report *methodwebtest.Report) { |
| 41 | + for _, target := range report.Targets { |
| 42 | + if target.Attempts == nil { |
| 43 | + continue |
| 44 | + } |
| 45 | + for _, attempt := range target.Attempts { |
| 46 | + if attempt.Request == nil || attempt.Request.ResponseBody == nil { |
| 47 | + continue |
| 48 | + } |
| 49 | + finding := false |
| 50 | + if strings.Contains(*attempt.Request.ResponseBody, "56154") { |
| 51 | + finding = true |
| 52 | + } |
| 53 | + if !finding && attempt.Request.ResponseHeaders != nil { |
| 54 | + for _, headerValue := range attempt.Request.ResponseHeaders { |
| 55 | + if strings.Contains(headerValue, "56154") { |
| 56 | + finding = true |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + attempt.Finding = &finding |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments