Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
更新内容
Browse files Browse the repository at this point in the history
- [功能] 使用 `api` 支持配置反连和日志级别
- [优化] 提供 `api` 简易和高级两种使用代码
  • Loading branch information
4ra1n committed Sep 11, 2024
1 parent 867204b commit d143bce
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

更新日志:

- [功能] 使用 `api` 支持配置反连和日志级别
- [功能] 支持 `print` 语法在表达式中打印调试
- [BUG] 修复上版本 `api` 参数错误的问题
- [优化] 优化代码仅解析一次 `yaml` 脚本
- [优化] 提供 `api` 简易和高级两种使用代码

感谢以下用户的贡献:

Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,32 @@ func main() {
}
```

Advance Example

```go
func main() {
ctx := context.Background()
// NEW ADVANCE POC RUNNER
runner, err := NewPocRunnerEx(
ctx, // CONTEXT
"socks5://127.0.0.1:10808", // SOCKS PROXY
time.Second*10, // TIMEOUT
true, // DEBUG MODE
"dnslog.cn", // REVERSE CONFIG (dnslog.cn | interact.sh)
log.DebugLevel, // LOG LEVEL
)
if err != nil {
return
}
// RUN POC
report, err := runner.Run([]byte(poc), "https://example.com")
if err != nil {
return
}
fmt.Println(report)
}
```

## BUILD

WINDOWS: 参考 `build.bat`
Expand Down
42 changes: 30 additions & 12 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,58 @@ import (
"github.com/4ra1n/poc-runner/base"
"github.com/4ra1n/poc-runner/client"
"github.com/4ra1n/poc-runner/engine"
"github.com/4ra1n/poc-runner/log"
"github.com/4ra1n/poc-runner/rawhttp"
"github.com/4ra1n/poc-runner/reverse"
)

type PocRunner struct {
ctx context.Context
client *client.HttpClient
proxy string
timeout time.Duration
debug bool
ctx context.Context
client *client.HttpClient
proxy string
timeout time.Duration
reverseType string
logLevel int
debug bool
}

func NewPocRunner(ctx context.Context) (*PocRunner, error) {
return NewPocRunnerEx(ctx, rawhttp.DefaultNoProxy, rawhttp.DefaultTimeout, false)
return NewPocRunnerEx(
ctx,
rawhttp.DefaultNoProxy,
rawhttp.DefaultTimeout,
false,
"dnslog.cn",
log.InfoLevel,
)
}

func NewPocRunnerEx(
ctx context.Context,
proxy string,
timeout time.Duration,
debug bool) (*PocRunner, error) {
debug bool,
reverseType string,
logLevel int,
) (*PocRunner, error) {
log.SetLevel(logLevel)
c, err := client.NewHttpClient(proxy, timeout, debug)
if err != nil {
return nil, err
}
return &PocRunner{
client: c,
ctx: ctx,
proxy: proxy,
timeout: timeout,
debug: debug,
client: c,
ctx: ctx,
proxy: proxy,
timeout: timeout,
debug: debug,
reverseType: reverseType,
logLevel: logLevel,
}, nil
}

func (p *PocRunner) Run(input []byte, target string) (string, error) {
reverse.Type = p.reverseType
poc, err := engine.InitYamlPoCFromBytes(p.ctx, p.client, input)
pocList := base.NewList[*base.POC]()
pocList.Add(poc)
Expand Down
38 changes: 28 additions & 10 deletions api/all.go → api/api_advance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,32 @@
package api

import (
_ "github.com/4ra1n/poc-runner/base"
_ "github.com/4ra1n/poc-runner/client"
_ "github.com/4ra1n/poc-runner/engine"
_ "github.com/4ra1n/poc-runner/expression"
_ "github.com/4ra1n/poc-runner/log"
_ "github.com/4ra1n/poc-runner/proxy"
_ "github.com/4ra1n/poc-runner/rawhttp"
_ "github.com/4ra1n/poc-runner/reverse"
_ "github.com/4ra1n/poc-runner/util"
_ "github.com/4ra1n/poc-runner/xerr"
"context"
"fmt"
"testing"
"time"

"github.com/4ra1n/poc-runner/log"
)

func TestAdvanceAPI(t *testing.T) {
ctx := context.Background()
// NEW ADVANCE POC RUNNER
runner, err := NewPocRunnerEx(
ctx, // CONTEXT
"socks5://127.0.0.1:10808", // SOCKS PROXY
time.Second*10, // TIMEOUT
true, // DEBUG MODE
"dnslog.cn", // REVERSE CONFIG (dnslog.cn | interact.sh)
log.DebugLevel, // LOG LEVEL
)
if err != nil {
return
}
// RUN POC
report, err := runner.Run([]byte(poc), "https://example.com")
if err != nil {
return
}
fmt.Println(report)
}
File renamed without changes.

0 comments on commit d143bce

Please sign in to comment.