Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: katana execution cannot be started without closing the standard input pipe #708

Open
hktalent opened this issue Jan 1, 2024 · 0 comments
Labels
Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@hktalent
Copy link

hktalent commented Jan 1, 2024

projectdiscovery/nuclei#4560

same bug

var re1 = regexp.MustCompile(` +`)

func testCmd(s string, data string) {
	a := re1.Split(s, -1)
	//log.Println(strings.Join(a, "\n"))
	Cmd := exec.Command(a[0], a[1:]...)
	var err error
	var wt io.WriteCloser
	var wg sync.WaitGroup
	wg.Add(2)
	if wt, err = Cmd.StdinPipe(); nil == err {
		bufout := bufio.NewWriter(wt)
		go func() {
			defer wg.Done()
			bufout.Write([]byte(data + "\n"))
			/*
				I am not in a hurry to close wt here, there will be more uses in the future
				At this point I hope nuclei has started running and output the results
				But we found that if wt is not closed here, http will hang and will never start execution.
				In other words, it will not friendly process and execute the stream from time to time.
				When the stream becomes larger one by one, it will cause memory overflow, the same problem., tlsx does not have this problem. It can process the stream line by line in a friendly manner without waiting for the stream to be closed.
			*/
			bufout.Flush()
			//wt.Close()
		}()
	} else {
		fmt.Println(err)
	}
	if out, err1 := Cmd.StdoutPipe(); nil == err1 {
		go func() {
			defer wg.Done()
			buf := make([]byte, 4096) // 设置适当的缓冲区大小
			for {
				n, err8 := out.Read(buf)
				if 0 < n {
					os.Stdout.Write(buf[:n])
				}
				if err8 == io.EOF {
					break
				}
				if err8 != nil {
					log.Println(err8)
					break
				}
			}
		}()
	} else {
		log.Println(err)
	}
	if err4 := Cmd.Start(); nil != err4 {
		log.Println("Cmd.Start", err4)
	}

	if err6 := Cmd.Wait(); nil != err6 {
		log.Println("Cmd.Wait", err6)
	}
	wg.Wait()
	wt.Close()
}
func TestKatana(t *testing.T) {
	testCmd("katana -nc -silent -j -hl -system-chrome -headless-options '--blink-settings=\"imagesEnabled=false\",--enable-quic=\"imagesEnabled=false\"' -jc -kf all", "https://51pwn.com")
}

If it can friendly support line-by-line processing stream
This helps parse the results in one pass, including the results of other programs, and then give them continuous input of some parameters that need to be iterated over

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

No branches or pull requests

1 participant