How to use CloneTags method of lib Package

Best K6 code snippet using lib.CloneTags

check.go

Source:check.go Github

copy

Full Screen

1package lib2import (3 "fmt"4 "github.com/google/cel-go/cel"5 "github.com/shadow1ng/fscan/WebScan/info"6 "github.com/shadow1ng/fscan/common"7 "math/rand"8 "net/http"9 "net/url"10 "regexp"11 "sort"12 "strings"13 "sync"14 "time"15)16var (17 ceyeApi = "a78a1cb49d91fe09e01876078d1868b2"18 ceyeDomain = "7wtusr.ceye.io"19)20type Task struct {21 Req *http.Request22 Poc *Poc23}24func CheckMultiPoc(req *http.Request, pocs []*Poc, workers int) {25 tasks := make(chan Task)26 var wg sync.WaitGroup27 for i := 0; i < workers; i++ {28 go func() {29 for task := range tasks {30 isVul, _, name := executePoc(task.Req, task.Poc)31 if isVul {32 result := fmt.Sprintf("[+] %s %s %s", task.Req.URL, task.Poc.Name, name)33 common.LogSuccess(result)34 }35 wg.Done()36 }37 }()38 }39 for _, poc := range pocs {40 task := Task{41 Req: req,42 Poc: poc,43 }44 wg.Add(1)45 tasks <- task46 }47 wg.Wait()48 close(tasks)49}50func executePoc(oReq *http.Request, p *Poc) (bool, error, string) {51 var lock sync.Mutex52 c := NewEnvOption()53 c.UpdateCompileOptions(p.Set)54 if len(p.Sets) > 0 {55 setMap := make(map[string]string)56 for k := range p.Sets {57 setMap[k] = p.Sets[k][0]58 }59 c.UpdateCompileOptions(setMap)60 }61 env, err := NewEnv(&c)62 if err != nil {63 fmt.Printf("[-] %s environment creation error: %s\n", p.Name, err)64 return false, err, ""65 }66 req, err := ParseRequest(oReq)67 if err != nil {68 fmt.Printf("[-] %s ParseRequest error: %s\n", p.Name, err)69 return false, err, ""70 }71 variableMap := make(map[string]interface{})72 variableMap["request"] = req73 // 现在假定set中payload作为最后产出,那么先排序解析其他的自定义变量,更新map[string]interface{}后再来解析payload74 keys := make([]string, 0)75 keys1 := make([]string, 0)76 for k := range p.Set {77 if strings.Contains(strings.ToLower(p.Set[k]), "random") && strings.Contains(strings.ToLower(p.Set[k]), "(") {78 keys = append(keys, k) //优先放入调用random系列函数的变量79 } else {80 keys1 = append(keys1, k)81 }82 }83 sort.Strings(keys)84 sort.Strings(keys1)85 keys = append(keys, keys1...)86 for _, k := range keys {87 expression := p.Set[k]88 if k != "payload" {89 if expression == "newReverse()" {90 variableMap[k] = newReverse()91 continue92 }93 out, err := Evaluate(env, expression, variableMap)94 if err != nil {95 //fmt.Println(p.Name," poc_expression error",err)96 variableMap[k] = expression97 continue98 }99 switch value := out.Value().(type) {100 case *UrlType:101 variableMap[k] = UrlTypeToString(value)102 case int64:103 variableMap[k] = int(value)104 case []uint8:105 variableMap[k] = fmt.Sprintf("%s", out)106 default:107 variableMap[k] = fmt.Sprintf("%v", out)108 }109 }110 }111 if p.Set["payload"] != "" {112 out, err := Evaluate(env, p.Set["payload"], variableMap)113 if err != nil {114 //fmt.Println(p.Name," poc_payload error",err)115 return false, err, ""116 }117 variableMap["payload"] = fmt.Sprintf("%v", out)118 }119 setslen := 0120 haspayload := false121 var setskeys []string122 if len(p.Sets) > 0 {123 for _, rule := range p.Rules {124 for k := range p.Sets {125 if strings.Contains(rule.Body, "{{"+k+"}}") || strings.Contains(rule.Path, "{{"+k+"}}") {126 if strings.Contains(k, "payload") {127 haspayload = true128 }129 setslen++130 setskeys = append(setskeys, k)131 continue132 }133 for k2 := range rule.Headers {134 if strings.Contains(rule.Headers[k2], "{{"+k+"}}") {135 if strings.Contains(k, "payload") {136 haspayload = true137 }138 setslen++139 setskeys = append(setskeys, k)140 continue141 }142 }143 }144 }145 }146 success := false147 //爆破模式,比如tomcat弱口令148 if setslen > 0 {149 if haspayload {150 success, err = clusterpoc1(oReq, p, variableMap, req, env, setskeys)151 } else {152 success, err = clusterpoc(oReq, p, variableMap, req, env, setslen, setskeys)153 }154 return success, nil, ""155 }156 DealWithRule := func(rule Rules) (bool, error) {157 var (158 flag, ok bool159 )160 for k1, v1 := range variableMap {161 _, isMap := v1.(map[string]string)162 if isMap {163 continue164 }165 value := fmt.Sprintf("%v", v1)166 for k2, v2 := range rule.Headers {167 lock.Lock()168 rule.Headers[k2] = strings.ReplaceAll(v2, "{{"+k1+"}}", value)169 lock.Unlock()170 }171 rule.Path = strings.ReplaceAll(strings.TrimSpace(rule.Path), "{{"+k1+"}}", value)172 rule.Body = strings.ReplaceAll(strings.TrimSpace(rule.Body), "{{"+k1+"}}", value)173 }174 if oReq.URL.Path != "" && oReq.URL.Path != "/" {175 req.Url.Path = fmt.Sprint(oReq.URL.Path, rule.Path)176 } else {177 req.Url.Path = rule.Path178 }179 // 某些poc没有区分path和query,需要处理180 req.Url.Path = strings.ReplaceAll(req.Url.Path, " ", "%20")181 req.Url.Path = strings.ReplaceAll(req.Url.Path, "+", "%20")182 newRequest, _ := http.NewRequest(rule.Method, fmt.Sprintf("%s://%s%s", req.Url.Scheme, req.Url.Host, req.Url.Path), strings.NewReader(rule.Body))183 newRequest.Header = oReq.Header.Clone()184 for k, v := range rule.Headers {185 newRequest.Header.Set(k, v)186 }187 resp, err := DoRequest(newRequest, rule.FollowRedirects)188 if err != nil {189 return false, err190 }191 variableMap["response"] = resp192 // 先判断响应页面是否匹配search规则193 if rule.Search != "" {194 result := doSearch(strings.TrimSpace(rule.Search), string(resp.Body))195 if result != nil && len(result) > 0 { // 正则匹配成功196 for k, v := range result {197 variableMap[k] = v198 }199 } else {200 return false, nil201 }202 }203 out, err := Evaluate(env, rule.Expression, variableMap)204 if err != nil {205 return false, err206 }207 //fmt.Println(fmt.Sprintf("%v, %s", out, out.Type().TypeName()))208 //如果false不继续执行后续rule209 // 如果最后一步执行失败,就算前面成功了最终依旧是失败210 flag, ok = out.Value().(bool)211 if !ok {212 flag = false213 }214 return flag, nil215 }216 DealWithRules := func(rules []Rules) bool {217 successFlag := false218 for _, rule := range rules {219 flag, err := DealWithRule(rule)220 //if err != nil {221 // fmt.Printf("[-] %s Execute Rule error: %s\n",p.Name,err.Error())222 //}223 if err != nil || !flag { //如果false不继续执行后续rule224 successFlag = false // 如果其中一步为flag,则直接break225 break226 }227 successFlag = true228 }229 return successFlag230 }231 if len(p.Rules) > 0 {232 success = DealWithRules(p.Rules)233 } else { // Groups234 for name, rules := range p.Groups {235 success = DealWithRules(rules)236 if success {237 return success, nil, name238 }239 }240 }241 return success, nil, ""242}243func doSearch(re string, body string) map[string]string {244 r, err := regexp.Compile(re)245 if err != nil {246 return nil247 }248 result := r.FindStringSubmatch(body)249 names := r.SubexpNames()250 if len(result) > 1 && len(names) > 1 {251 paramsMap := make(map[string]string)252 for i, name := range names {253 if i > 0 && i <= len(result) {254 paramsMap[name] = result[i]255 }256 }257 return paramsMap258 }259 return nil260}261func newReverse() *Reverse {262 letters := "1234567890abcdefghijklmnopqrstuvwxyz"263 randSource := rand.New(rand.NewSource(time.Now().Unix()))264 sub := RandomStr(randSource, letters, 8)265 if true {266 //默认不开启dns解析267 return &Reverse{}268 }269 urlStr := fmt.Sprintf("http://%s.%s", sub, ceyeDomain)270 u, _ := url.Parse(urlStr)271 return &Reverse{272 Url: ParseUrl(u),273 Domain: u.Hostname(),274 Ip: "",275 IsDomainNameServer: false,276 }277}278func clusterpoc(oReq *http.Request, p *Poc, variableMap map[string]interface{}, req *Request, env *cel.Env, slen int, keys []string) (success bool, err error) {279 for _, rule := range p.Rules {280 for k1, v1 := range variableMap {281 if IsContain(keys, k1) {282 continue283 }284 _, isMap := v1.(map[string]string)285 if isMap {286 continue287 }288 value := fmt.Sprintf("%v", v1)289 for k2, v2 := range rule.Headers {290 rule.Headers[k2] = strings.ReplaceAll(v2, "{{"+k1+"}}", value)291 }292 rule.Path = strings.ReplaceAll(strings.TrimSpace(rule.Path), "{{"+k1+"}}", value)293 rule.Body = strings.ReplaceAll(strings.TrimSpace(rule.Body), "{{"+k1+"}}", value)294 }295 n := 0296 for k := range p.Sets {297 if strings.Contains(rule.Body, "{{"+k+"}}") || strings.Contains(rule.Path, "{{"+k+"}}") {298 n++299 continue300 }301 for k2 := range rule.Headers {302 if strings.Contains(rule.Headers[k2], "{{"+k+"}}") {303 n++304 continue305 }306 }307 }308 if n == 0 {309 success, err = clustersend(oReq, variableMap, req, env, rule)310 if err != nil {311 return false, err312 }313 if success == false {314 break315 }316 }317 if slen == 1 {318 look1:319 for _, var1 := range p.Sets[keys[0]] {320 rule1 := cloneRules(rule)321 for k2, v2 := range rule1.Headers {322 rule1.Headers[k2] = strings.ReplaceAll(v2, "{{"+keys[0]+"}}", var1)323 }324 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+keys[0]+"}}", var1)325 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+keys[0]+"}}", var1)326 success, err = clustersend(oReq, variableMap, req, env, rule1)327 if err != nil {328 return false, err329 }330 if success == true {331 break look1332 }333 }334 if success == false {335 break336 }337 }338 if slen == 2 {339 look2:340 for _, var1 := range p.Sets[keys[0]] {341 for _, var2 := range p.Sets[keys[1]] {342 rule1 := cloneRules(rule)343 for k2, v2 := range rule1.Headers {344 rule1.Headers[k2] = strings.ReplaceAll(v2, "{{"+keys[0]+"}}", var1)345 rule1.Headers[k2] = strings.ReplaceAll(rule1.Headers[k2], "{{"+keys[1]+"}}", var2)346 }347 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+keys[0]+"}}", var1)348 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+keys[0]+"}}", var1)349 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+keys[1]+"}}", var2)350 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+keys[1]+"}}", var2)351 success, err = clustersend(oReq, variableMap, req, env, rule1)352 if err != nil {353 return false, err354 }355 if success == true {356 break look2357 }358 }359 }360 if success == false {361 break362 }363 }364 if slen == 3 {365 look3:366 for _, var1 := range p.Sets[keys[0]] {367 for _, var2 := range p.Sets[keys[1]] {368 for _, var3 := range p.Sets[keys[2]] {369 rule1 := cloneRules(rule)370 for k2, v2 := range rule1.Headers {371 rule1.Headers[k2] = strings.ReplaceAll(v2, "{{"+keys[0]+"}}", var1)372 rule1.Headers[k2] = strings.ReplaceAll(rule1.Headers[k2], "{{"+keys[1]+"}}", var2)373 rule1.Headers[k2] = strings.ReplaceAll(rule1.Headers[k2], "{{"+keys[2]+"}}", var3)374 }375 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+keys[0]+"}}", var1)376 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+keys[0]+"}}", var1)377 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+keys[1]+"}}", var2)378 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+keys[1]+"}}", var2)379 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+keys[2]+"}}", var3)380 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+keys[2]+"}}", var3)381 success, err = clustersend(oReq, variableMap, req, env, rule)382 if err != nil {383 return false, err384 }385 if success == true {386 break look3387 }388 }389 }390 }391 if success == false {392 break393 }394 }395 }396 return success, nil397}398func clusterpoc1(oReq *http.Request, p *Poc, variableMap map[string]interface{}, req *Request, env *cel.Env, keys []string) (success bool, err error) {399 setMap := make(map[string]interface{})400 for k := range p.Sets {401 setMap[k] = p.Sets[k][0]402 }403 setMapbak := cloneMap1(setMap)404 for _, rule := range p.Rules {405 for k1, v1 := range variableMap {406 if IsContain(keys, k1) {407 continue408 }409 _, isMap := v1.(map[string]string)410 if isMap {411 continue412 }413 value := fmt.Sprintf("%v", v1)414 for k2, v2 := range rule.Headers {415 rule.Headers[k2] = strings.ReplaceAll(v2, "{{"+k1+"}}", value)416 }417 rule.Path = strings.ReplaceAll(strings.TrimSpace(rule.Path), "{{"+k1+"}}", value)418 rule.Body = strings.ReplaceAll(strings.TrimSpace(rule.Body), "{{"+k1+"}}", value)419 }420 varset := []string{}421 varpay := []string{}422 n := 0423 for k := range p.Sets {424 // 1. 如果rule中需要修改 {{k}} 如username、payload425 if strings.Contains(rule.Body, "{{"+k+"}}") || strings.Contains(rule.Path, "{{"+k+"}}") {426 if strings.Contains(k, "payload") {427 varpay = append(varpay, k)428 } else {429 varset = append(varset, k)430 }431 n++432 continue433 }434 for k2 := range rule.Headers {435 if strings.Contains(rule.Headers[k2], "{{"+k+"}}") {436 if strings.Contains(k, "payload") {437 varpay = append(varpay, k)438 } else {439 varset = append(varset, k)440 }441 n++442 continue443 }444 }445 }446 for _, key := range varpay {447 v := fmt.Sprintf("%s", setMap[key])448 for k := range p.Sets {449 if strings.Contains(v, k) {450 if !IsContain(varset, k) && !IsContain(varpay, k) {451 varset = append(varset, k)452 }453 }454 }455 }456 if n == 0 {457 success, err = clustersend(oReq, variableMap, req, env, rule)458 if err != nil {459 return false, err460 }461 if success == false {462 break463 }464 }465 if len(varset) == 1 {466 look1:467 // (var1 tomcat ,keys[0] username)468 for _, var1 := range p.Sets[varset[0]] {469 setMap := cloneMap1(setMapbak)470 setMap[varset[0]] = var1471 evalset(env, setMap)472 rule1 := cloneRules(rule)473 for k2, v2 := range rule1.Headers {474 rule1.Headers[k2] = strings.ReplaceAll(v2, "{{"+varset[0]+"}}", var1)475 for _, key := range varpay {476 rule1.Headers[k2] = strings.ReplaceAll(rule1.Headers[k2], "{{"+key+"}}", fmt.Sprintf("%v", setMap[key]))477 }478 }479 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+varset[0]+"}}", var1)480 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+varset[0]+"}}", var1)481 for _, key := range varpay {482 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+key+"}}", fmt.Sprintf("%v", setMap[key]))483 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+key+"}}", fmt.Sprintf("%v", setMap[key]))484 }485 success, err = clustersend(oReq, variableMap, req, env, rule)486 if err != nil {487 return false, err488 }489 if success == true {490 common.LogSuccess(fmt.Sprintf("[+] %s://%s%s %s", req.Url.Scheme, req.Url.Host, req.Url.Path, var1))491 break look1492 }493 }494 if success == false {495 break496 }497 }498 if len(varset) == 2 {499 look2:500 // (var1 tomcat ,keys[0] username)501 for _, var1 := range p.Sets[varset[0]] { //username502 for _, var2 := range p.Sets[varset[1]] { //password503 setMap := cloneMap1(setMapbak)504 setMap[varset[0]] = var1505 setMap[varset[1]] = var2506 evalset(env, setMap)507 rule1 := cloneRules(rule)508 for k2, v2 := range rule1.Headers {509 rule1.Headers[k2] = strings.ReplaceAll(v2, "{{"+varset[0]+"}}", var1)510 rule1.Headers[k2] = strings.ReplaceAll(rule1.Headers[k2], "{{"+varset[1]+"}}", var2)511 for _, key := range varpay {512 rule1.Headers[k2] = strings.ReplaceAll(rule1.Headers[k2], "{{"+key+"}}", fmt.Sprintf("%v", setMap[key]))513 }514 }515 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+varset[0]+"}}", var1)516 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+varset[0]+"}}", var1)517 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+varset[1]+"}}", var2)518 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+varset[1]+"}}", var2)519 for _, key := range varpay {520 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+key+"}}", fmt.Sprintf("%v", setMap[key]))521 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+key+"}}", fmt.Sprintf("%v", setMap[key]))522 }523 success, err = clustersend(oReq, variableMap, req, env, rule1)524 if err != nil {525 return false, err526 }527 if success == true {528 common.LogSuccess(fmt.Sprintf("[+] %s://%s%s %s %s", req.Url.Scheme, req.Url.Host, req.Url.Path, var1, var2))529 break look2530 }531 }532 }533 if success == false {534 break535 }536 }537 if len(varset) == 3 {538 look3:539 for _, var1 := range p.Sets[keys[0]] {540 for _, var2 := range p.Sets[keys[1]] {541 for _, var3 := range p.Sets[keys[2]] {542 setMap := cloneMap1(setMapbak)543 setMap[varset[0]] = var1544 setMap[varset[1]] = var2545 evalset(env, setMap)546 rule1 := cloneRules(rule)547 for k2, v2 := range rule1.Headers {548 rule1.Headers[k2] = strings.ReplaceAll(v2, "{{"+keys[0]+"}}", var1)549 rule1.Headers[k2] = strings.ReplaceAll(rule1.Headers[k2], "{{"+keys[1]+"}}", var2)550 rule1.Headers[k2] = strings.ReplaceAll(rule1.Headers[k2], "{{"+keys[2]+"}}", var3)551 for _, key := range varpay {552 rule1.Headers[k2] = strings.ReplaceAll(rule1.Headers[k2], "{{"+key+"}}", fmt.Sprintf("%v", setMap[key]))553 }554 }555 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+keys[0]+"}}", var1)556 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+keys[0]+"}}", var1)557 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+keys[1]+"}}", var2)558 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+keys[1]+"}}", var2)559 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+keys[2]+"}}", var3)560 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+keys[2]+"}}", var3)561 for _, key := range varpay {562 rule1.Path = strings.ReplaceAll(strings.TrimSpace(rule1.Path), "{{"+key+"}}", fmt.Sprintf("%v", setMap[key]))563 rule1.Body = strings.ReplaceAll(strings.TrimSpace(rule1.Body), "{{"+key+"}}", fmt.Sprintf("%v", setMap[key]))564 }565 success, err = clustersend(oReq, variableMap, req, env, rule)566 if err != nil {567 return false, err568 }569 if success == true {570 common.LogSuccess(fmt.Sprintf("[+] %s://%s%s %s %s %s", req.Url.Scheme, req.Url.Host, req.Url.Path, var1, var2, var3))571 break look3572 }573 }574 }575 }576 if success == false {577 break578 }579 }580 }581 return success, nil582}583func clustersend(oReq *http.Request, variableMap map[string]interface{}, req *Request, env *cel.Env, rule Rules) (bool, error) {584 if oReq.URL.Path != "" && oReq.URL.Path != "/" {585 req.Url.Path = fmt.Sprint(oReq.URL.Path, rule.Path)586 } else {587 req.Url.Path = rule.Path588 }589 // 某些poc没有区分path和query,需要处理590 req.Url.Path = strings.ReplaceAll(req.Url.Path, " ", "%20")591 req.Url.Path = strings.ReplaceAll(req.Url.Path, "+", "%20")592 newRequest, _ := http.NewRequest(rule.Method, fmt.Sprintf("%s://%s%s", req.Url.Scheme, req.Url.Host, req.Url.Path), strings.NewReader(rule.Body))593 newRequest.Header = oReq.Header.Clone()594 for k, v := range rule.Headers {595 newRequest.Header.Set(k, v)596 }597 resp, err := DoRequest(newRequest, rule.FollowRedirects)598 if err != nil {599 return false, err600 }601 variableMap["response"] = resp602 // 先判断响应页面是否匹配search规则603 if rule.Search != "" {604 result := doSearch(strings.TrimSpace(rule.Search), string(resp.Body))605 if result != nil && len(result) > 0 { // 正则匹配成功606 for k, v := range result {607 variableMap[k] = v608 }609 //return false, nil610 } else {611 return false, nil612 }613 }614 out, err := Evaluate(env, rule.Expression, variableMap)615 if err != nil {616 return false, err617 }618 //fmt.Println(fmt.Sprintf("%v, %s", out, out.Type().TypeName()))619 if fmt.Sprintf("%v", out) == "false" { //如果false不继续执行后续rule620 return false, err // 如果最后一步执行失败,就算前面成功了最终依旧是失败621 }622 return true, err623}624func cloneRules(tags Rules) Rules {625 cloneTags := Rules{}626 cloneTags.Method = tags.Method627 cloneTags.Path = tags.Path628 cloneTags.Body = tags.Body629 cloneTags.Search = tags.Search630 cloneTags.FollowRedirects = tags.FollowRedirects631 cloneTags.Expression = tags.Expression632 cloneTags.Headers = cloneMap(tags.Headers)633 return cloneTags634}635func cloneMap(tags map[string]string) map[string]string {636 cloneTags := make(map[string]string)637 for k, v := range tags {638 cloneTags[k] = v639 }640 return cloneTags641}642func cloneMap1(tags map[string]interface{}) map[string]interface{} {643 cloneTags := make(map[string]interface{})644 for k, v := range tags {645 cloneTags[k] = v646 }647 return cloneTags648}649func IsContain(items []string, item string) bool {650 for _, eachItem := range items {651 if eachItem == item {652 return true653 }654 }655 return false656}657func evalset(env *cel.Env, variableMap map[string]interface{}) {658 for k := range variableMap {659 expression := fmt.Sprintf("%v", variableMap[k])660 if !strings.Contains(k, "payload") {661 out, err := Evaluate(env, expression, variableMap)662 if err != nil {663 //fmt.Println(err)664 variableMap[k] = expression665 continue666 }667 switch value := out.Value().(type) {668 case *UrlType:669 variableMap[k] = UrlTypeToString(value)670 case int64:671 variableMap[k] = fmt.Sprintf("%v", value)672 case []uint8:673 variableMap[k] = fmt.Sprintf("%v", out)674 default:675 variableMap[k] = fmt.Sprintf("%v", out)676 }677 }678 }679 for k := range variableMap {680 expression := fmt.Sprintf("%v", variableMap[k])681 if strings.Contains(k, "payload") {682 out, err := Evaluate(env, expression, variableMap)683 if err != nil {684 fmt.Println(err)685 variableMap[k] = expression686 } else {687 variableMap[k] = fmt.Sprintf("%v", out)688 }689 }690 }691}692func CheckInfoPoc(infostr string) string {693 for _, poc := range info.PocDatas {694 if strings.Compare(poc.Name, infostr) == 0 {695 return poc.Alias696 }697 }698 return ""699}...

Full Screen

Full Screen

CloneTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 lib.CloneTags()4}5import (6func main() {7 lib.CloneTags()8}9The above code is in 2 different packages. The lib is a package which is imported by 1.go and 2.go. The lib package has a CloneTags method which is used by 1.go and 2.go. When I run go build on each of the main files, I get the following error:10 /usr/local/go/src/github.com/abc/pkg/lib (from $GOROOT)11 /home/user/go/src/github.com/abc/pkg/lib (from $GOPATH)12 /usr/local/go/src/github.com/abc/pkg/lib (from $GOROOT)13 /home/user/go/src/github.com/abc/pkg/lib (from $GOPATH)14 /usr/local/go/src/github.com/abc/pkg/lib (from $GOROOT)15 /home/user/go/src/github.com/abc/pkg/lib (from $GOPATH)16 /usr/local/go/src/github.com/abc/pkg/lib (from $GOROOT)

Full Screen

Full Screen

CloneTags

Using AI Code Generation

copy

Full Screen

1func main() {2 lib := new(lib.Lib)3 lib.CloneTags()4}5import (6type Lib struct {7}8func (l *Lib) CloneTags() {9 fmt.Println("Cloning Tags")10}

Full Screen

Full Screen

CloneTags

Using AI Code Generation

copy

Full Screen

1func main() {2}3import (4func CloneTags(url string, tag string) {5 res, err := http.Get(url)6 if err != nil {7 log.Fatal(err)8 }9 defer res.Body.Close()10 if res.StatusCode != 200 {11 log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)12 }13 doc, err := goquery.NewDocumentFromReader(res.Body)14 if err != nil {15 log.Fatal(err)16 }17 doc.Find(tag).Each(func(i int, s *goquery.Selection) {18 fmt.Println(s.Text())19 })20}21import (22func CloneTags(url string, tag string) {23 res, err := http.Get(url)24 if err != nil {25 log.Fatal(err)26 }27 defer res.Body.Close()28 if res.StatusCode != 200 {29 log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)30 }31 doc, err := goquery.NewDocumentFromReader(res.Body)32 if err != nil {33 log.Fatal(err)34 }35 doc.Find(tag).Each(func(i int, s *goquery.Selection) {36 fmt.Println(s.Text())37 })38}

Full Screen

Full Screen

CloneTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("libtags version:", libtags.Version)4 tags := libtags.NewTags()5 tags.Add("a", "1")6 tags.Add("b", "2")7 tags.Add("c", "3")8 tags.Add("d", "4")9 tags.Add("e", "5")10 tags.Add("f", "6")11 fmt.Println("tags:", tags)12 tags2 := tags.CloneTags()13 fmt.Println("tags2:", tags2)14 tags2.Add("g", "7")15 fmt.Println("tags2:", tags2)16 fmt.Println("tags:", tags)17}18import (19func main() {20 fmt.Println("libtags version:", libtags.Version)21 fmt.Println("tags:", tags)22 tags2 := tags.CloneTags()23 fmt.Println("tags2:", tags2)24 tags2.Add("g", "7")25 fmt.Println("tags2:", tags2)26 fmt.Println("tags:", tags)27}

Full Screen

Full Screen

CloneTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 lib := lib.NewLib()4 lib.CloneTags()5 fmt.Println("Done")6}7import (8func main() {9 lib := lib.NewLib()10 lib.CloneTags()11 fmt.Println("Done")12}13import (14func main() {15 lib := lib.NewLib()16 lib.CloneTags()17 fmt.Println("Done")18}19import (20func main() {21 lib := lib.NewLib()22 lib.CloneTags()23 fmt.Println("Done")24}25import (26func main() {27 lib := lib.NewLib()28 lib.CloneTags()29 fmt.Println("Done")30}31import (32func main() {33 lib := lib.NewLib()34 lib.CloneTags()35 fmt.Println("Done")36}37import (38func main() {

Full Screen

Full Screen

CloneTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 data, err := ioutil.ReadFile("1.go")4 if err != nil {5 fmt.Println("File reading error", err)6 }7 vm := otto.New()8 vm.Set("lib", map[string]interface{}{9 })10 vm.Run("var lib = require('lib')")11 vm.Run(string(data))12 value, _ := vm.Get("result")13 fmt.Println(value)14}15func CloneTags (tag string) string {16 return strings.Replace(tag, " ", "_", -1)17}

Full Screen

Full Screen

CloneTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 r, _ := git.OpenRepository("/home/andrewstuart/.git")4 tags, _ := r.CloneTags()5 for _, tag := range tags {6 fmt.Println(tag)7 }8}9import (10func main() {11 r, _ := git.OpenRepository("/home/andrewstuart/.git")12 tags, _ := r.CloneTags()13 for _, tag := range tags {14 fmt.Println(tag)15 }16}17import (18func main() {19 r, _ := git.OpenRepository("/home/andrewstuart/.git")20 tags, _ := r.CloneTags()21 for _, tag := range tags {22 fmt.Println(tag)23 }24}25import (26func main() {27 r, _ := git.OpenRepository("/home/andrewstuart/.git")28 tags, _ := r.CloneTags()29 for _, tag := range tags {30 fmt.Println(tag)31 }32}33import (34func main() {35 r, _ := git.OpenRepository("/home/andrewstuart/.git")36 tags, _ := r.CloneTags()37 for _, tag := range tags {38 fmt.Println(tag)39 }40}

Full Screen

Full Screen

CloneTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var args struct {4 }5 arg.MustParse(&args)6 err := lib.CloneTags(args.SourceTag, args.TargetTag)7 if err != nil {8 fmt.Println(err)9 }10}11import (12func main() {13 var args struct {14 }15 arg.MustParse(&args)16 err := lib.CloneTags(args.SourceTag, args.TargetTag)17 if err != nil {18 fmt.Println(err)19 }20}21import (22func main() {23 var args struct {24 }25 arg.MustParse(&args)26 err := lib.CloneTags(args.SourceTag, args.TargetTag)27 if err != nil {28 fmt.Println(err)29 }30}31import (32func main() {33 var args struct {34 }35 arg.MustParse(&args)36 err := lib.CloneTags(args.SourceTag, args.TargetTag)37 if err != nil {38 fmt.Println(err)39 }40}41import (42func main() {43 var args struct {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful