Skip to content

Commit 8c2425c

Browse files
committed
v1.2.1
1 parent 6285107 commit 8c2425c

File tree

5 files changed

+82
-149
lines changed

5 files changed

+82
-149
lines changed

afrog-pocs/vulnerability/grafana-file-read.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
id: grafana-file-read
22

33
info:
4-
name: grafana-default-password
5-
author: For3stCo1d (https://github.com/For3stCo1d)
4+
name: Grafana v8.x Arbitrary File Read
5+
author: zan8in
66
severity: high
77
description: |
88
app="Grafana_Labs-公司产品"

pkg/core/celprogram.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -449,28 +449,32 @@ func reverseCheck(r *proto.Reverse, timeout int64) bool {
449449
req, _ := http.NewRequest("GET", urlStr, nil)
450450

451451
time.Sleep(time.Second * time.Duration(timeout))
452+
// fmt.Println(sub)
452453

453454
redirectsCount := 0
454455
for {
455456
resp, err := FastClientReverse.SampleHTTPRequest(req)
456457
if err != nil {
458+
// fmt.Println("rediSampleHTTPRequest", err.Error())
457459
log.Log().Error(err.Error())
458460
return false
459461
}
460462

461463
if !bytes.Contains(resp.Body, []byte(`"data": []`)) && bytes.Contains(resp.Body, []byte(`{"code": 200`)) { // api返回结果不为空
464+
// fmt.Println(string(resp.Body))
462465
return true
463466
}
464467

465468
if bytes.Contains(resp.Body, []byte(`<title>503`)) { // api返回结果不为空
466469
redirectsCount++
470+
// fmt.Println("redirectsCount++", redirectsCount)
467471
if redirectsCount > 1 {
468472
return false
469473
}
470474
utils.RandSleep(500)
471475
continue
472476
}
473-
477+
// fmt.Println(string(resp.Body))
474478
return false
475479
}
476480
}

pkg/core/checker.go

+33-139
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"net/http"
66
"net/url"
77
"strings"
8-
"sync"
98

109
"github.com/google/cel-go/checker/decls"
1110
"github.com/zan8in/afrog/pkg/config"
@@ -18,157 +17,51 @@ import (
1817
)
1918

2019
type Checker struct {
21-
Options *sync.Pool
22-
Target *sync.Pool
23-
PocItem *sync.Pool
24-
PocHandler *sync.Pool
25-
OriginalRequest *sync.Pool
26-
VariableMap *sync.Pool
27-
Result *sync.Pool
28-
CustomLib *sync.Pool
29-
FastClient *sync.Pool
20+
Options *config.Options
21+
OriginalRequest *http.Request
22+
VariableMap map[string]interface{}
23+
Result *Result
24+
CustomLib *CustomLib
25+
FastClient *http2.FastClient
3026
}
3127

3228
var ReverseCeyeApiKey string
3329
var ReverseCeyeDomain string
3430

35-
func NewChecker(options *config.Options, target string, pocItem poc.Poc) *Checker {
36-
ReverseCeyeApiKey = options.Config.Reverse.Ceye.ApiKey
37-
ReverseCeyeDomain = options.Config.Reverse.Ceye.Domain
38-
39-
if len(ReverseCeyeApiKey) == 0 || len(ReverseCeyeDomain) == 0 {
40-
log.Log().Error("Rerverse CeyeApiKey or CeyeDomain is Empty.")
41-
return nil
42-
}
43-
44-
return &Checker{
45-
Options: &sync.Pool{
46-
New: func() interface{} {
47-
return options
48-
},
49-
},
50-
Target: &sync.Pool{
51-
New: func() interface{} {
52-
return target
53-
},
54-
},
55-
PocItem: &sync.Pool{
56-
New: func() interface{} {
57-
return &pocItem
58-
},
59-
},
60-
PocHandler: &sync.Pool{
61-
New: func() interface{} {
62-
pocHandler := ""
63-
if strings.Contains(pocItem.Expression, "&&") && !strings.Contains(pocItem.Expression, "||") {
64-
pocHandler = poc.ALLAND
65-
}
66-
if strings.Contains(pocItem.Expression, "||") && !strings.Contains(pocItem.Expression, "&&") {
67-
pocHandler = poc.ALLOR
68-
}
69-
return pocHandler
70-
},
71-
},
72-
OriginalRequest: &sync.Pool{
73-
New: func() interface{} {
74-
return &http.Request{}
75-
},
76-
},
77-
VariableMap: &sync.Pool{
78-
New: func() interface{} {
79-
return make(map[string]interface{})
80-
},
81-
},
82-
Result: &sync.Pool{
83-
New: func() interface{} {
84-
return &Result{
85-
Target: target,
86-
PocInfo: &pocItem,
87-
Output: options.Output,
88-
}
89-
},
90-
},
91-
CustomLib: &sync.Pool{
92-
New: func() interface{} {
93-
return NewCustomLib()
94-
},
95-
},
96-
FastClient: &sync.Pool{
97-
New: func() interface{} {
98-
return &http2.FastClient{}
99-
},
100-
},
101-
}
102-
}
103-
104-
func (c *Checker) ReleaseVariableMap(vmap map[string]interface{}) {
105-
if vmap != nil {
106-
vmap = nil
107-
c.VariableMap.Put(vmap)
108-
}
109-
}
110-
111-
func (c *Checker) ReleaseTarget(r string) {
112-
if len(r) > 0 {
113-
r = ""
114-
c.Target.Put(r)
115-
}
116-
}
117-
118-
func (c *Checker) ReleaseHandler(h string) {
119-
if len(h) > 0 {
120-
h = ""
121-
c.Target.Put(h)
122-
}
123-
}
124-
125-
func (c *Checker) ReleaseOriginalRequest(o *http.Request) {
126-
if o != nil {
127-
*o = http.Request{}
128-
c.OriginalRequest.Put(o)
129-
}
130-
}
131-
13231
var FastClientReverse *http2.FastClient // 用于 reverse http client
13332

134-
func (c *Checker) Check() (err error) {
33+
func (c *Checker) Check(target string, pocItem poc.Poc) (err error) {
34+
35+
options := c.Options
13536

136-
options := c.Options.Get().(*config.Options)
137-
defer c.Options.Put(options)
37+
ReverseCeyeApiKey = options.Config.Reverse.Ceye.ApiKey
38+
ReverseCeyeDomain = options.Config.Reverse.Ceye.Domain
13839

139-
fc := c.FastClient.Get().(*http2.FastClient)
40+
fc := c.FastClient
14041
fc.Client = http2.New(options)
14142
fc.DialTimeout = options.Config.ConfigHttp.DialTimeout
142-
defer c.FastClient.Put(fc)
143-
defer fc.Reset()
144-
145-
variableMap := c.VariableMap.Get().(map[string]interface{})
146-
defer c.ReleaseVariableMap(variableMap)
147-
148-
target := c.Target.Get().(string)
149-
defer c.ReleaseTarget(target)
15043

151-
pocItem := c.PocItem.Get().(*poc.Poc)
152-
defer c.PocItem.Put(pocItem)
153-
defer pocItem.Reset()
44+
variableMap := c.VariableMap
15445

155-
result := c.Result.Get().(*Result)
156-
defer c.Result.Put(result)
157-
defer result.Reset()
46+
result := c.Result
47+
result.Target = target
48+
result.PocInfo = &pocItem
15849

159-
customLib := c.CustomLib.Get().(*CustomLib)
160-
defer c.CustomLib.Put(customLib)
161-
defer customLib.Reset()
50+
customLib := c.CustomLib
16251

163-
originalRequest := c.OriginalRequest.Get().(*http.Request)
164-
defer c.ReleaseOriginalRequest(originalRequest)
52+
originalRequest := c.OriginalRequest
16553

166-
pocHandler := c.PocHandler.Get().(string)
167-
defer c.ReleaseHandler(pocHandler)
54+
pocHandler := ""
55+
if strings.Contains(pocItem.Expression, "&&") && !strings.Contains(pocItem.Expression, "||") {
56+
pocHandler = poc.ALLAND
57+
}
58+
if strings.Contains(pocItem.Expression, "||") && !strings.Contains(pocItem.Expression, "&&") {
59+
pocHandler = poc.ALLOR
60+
}
16861

16962
// update request variablemap
170-
tempRequest := http2.AcquireProtoRequestPool()
171-
defer http2.ReleaseProtoRequestPool(tempRequest)
63+
// tempRequest := http2.AcquireProtoRequestPool()
64+
// defer http2.ReleaseProtoRequestPool(tempRequest)
17265
if pocItem.Transport != "tcp" && pocItem.Transport != "udp" {
17366
if !strings.HasPrefix(target, "http://") && !strings.HasPrefix(target, "https://") {
17467
target = "http://" + target
@@ -183,7 +76,9 @@ func (c *Checker) Check() (err error) {
18376
return err
18477
}
18578

186-
tempRequest, err = http2.ParseRequest(originalRequest)
79+
tempRequest, err := http2.ParseRequest(originalRequest)
80+
variableMap["request"] = tempRequest
81+
18782
if err != nil {
18883
log.Log().Error(fmt.Sprintf("ParseRequest err, %s", err.Error()))
18984
result.IsVul = false
@@ -198,7 +93,6 @@ func (c *Checker) Check() (err error) {
19893
originalRequest.Header.Set("User-Agent", utils.RandomUA())
19994
}
20095
}
201-
variableMap["request"] = tempRequest
20296

20397
// update set cel and variablemap
20498
if len(pocItem.Set) > 0 {
@@ -308,9 +202,9 @@ func (c *Checker) UpdateVariableMap(args yaml.MapSlice, variableMap map[string]i
308202
customLib.UpdateCompileOption(key, decls.NewObjectType("proto.Reverse"))
309203

310204
// if reverse(),initilize a fasthttpclient
311-
FastClientReverse = c.FastClient.Get().(*http2.FastClient)
312-
FastClientReverse.DialTimeout = c.Options.Get().(*config.Options).Config.ConfigHttp.DialTimeout
313-
FastClientReverse.Client = http2.New(c.Options.Get().(*config.Options))
205+
FastClientReverse = c.FastClient
206+
FastClientReverse.DialTimeout = c.Options.Config.ConfigHttp.DialTimeout
207+
FastClientReverse.Client = http2.New(c.Options)
314208
continue
315209
}
316210

pkg/core/engine.go

+33
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
11
package core
22

33
import (
4+
"net/http"
5+
"sync"
6+
47
"github.com/zan8in/afrog/pkg/config"
8+
http2 "github.com/zan8in/afrog/pkg/protocols/http"
59
)
610

11+
var CheckerPool = sync.Pool{
12+
New: func() interface{} {
13+
return &Checker{
14+
Options: &config.Options{},
15+
OriginalRequest: &http.Request{},
16+
VariableMap: make(map[string]interface{}),
17+
Result: &Result{},
18+
CustomLib: NewCustomLib(),
19+
FastClient: &http2.FastClient{},
20+
}
21+
},
22+
}
23+
24+
func (e *Engine) AcquireChecker() *Checker {
25+
c := CheckerPool.Get().(*Checker)
26+
c.Options = e.options
27+
c.Result.Output = e.options.Output
28+
return c
29+
}
30+
31+
func (e *Engine) ReleaseChecker(c *Checker) {
32+
*c.OriginalRequest = http.Request{}
33+
c.VariableMap = make(map[string]interface{})
34+
c.Result = &Result{}
35+
c.CustomLib = NewCustomLib()
36+
c.FastClient = &http2.FastClient{}
37+
CheckerPool.Put(c)
38+
}
39+
740
type Engine struct {
841
workPool *WorkPool
942
options *config.Options

pkg/core/excute.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@ func (e *Engine) executeTargets(poc1 poc.Poc) {
5555
}
5656

5757
func (e *Engine) executeExpression(target string, poc poc.Poc) {
58-
defer func() {
59-
if r := recover(); r != nil {
60-
log.Log().Error("gorutine recover() error from pkg/core/exccute/executeExpression")
61-
}
62-
}()
58+
// defer func() {
59+
// if r := recover(); r != nil {
60+
// log.Log().Error("gorutine recover() error from pkg/core/exccute/executeExpression")
61+
// }
62+
// }()
6363

64-
c := NewChecker(e.options, target, poc)
65-
if err := c.Check(); err != nil {
64+
// c := NewChecker(e.options, target, poc)
65+
c := e.AcquireChecker()
66+
defer e.ReleaseChecker(c)
67+
if err := c.Check(target, poc); err != nil {
6668
log.Log().Error(err.Error())
6769
}
6870
}

0 commit comments

Comments
 (0)