这是indexloc提供的服务,不要输入任何密码
Skip to content

Update random seed logic #262

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

Merged
merged 5 commits into from
Jul 23, 2020
Merged

Update random seed logic #262

merged 5 commits into from
Jul 23, 2020

Conversation

bjhulst
Copy link
Contributor

@bjhulst bjhulst commented Jul 13, 2020

In GO rand.Intn is not really random at all unless you change the seed value before calling it.

@bjhulst bjhulst mentioned this pull request Jul 13, 2020
@joohoi
Copy link
Member

joohoi commented Jul 13, 2020

Thanks for the change. The rand.seed is however already called in job.go, as it only needs to be seeded once per execution (or job like here). It's much faster that way instead of applying a new seed for every call of the helper function.

This PR could however add a comment pointing that out for all the future readers of the code (myself included). For reference, the seed is set here:

rand.Seed(time.Now().UnixNano())

@bjhulst
Copy link
Contributor Author

bjhulst commented Jul 13, 2020

Actually I found this issue when running with "calibration-enable" during "several times" and it always gave me the error message with the same random string.... :-)

Current code-base gives:
$ ./ffuf -ac -w words.txt -u https://notexisting.com/FUZZ
Error in autocalibration, exiting: Get https://notexisting.com/adminXVlBzgbaiCMRAjWw/: connect: no route to host
$ ./ffuf -ac -w words.txt -u https://notexisting.com/FUZZ
Error in autocalibration, exiting: Get https://notexisting.com/adminXVlBzgbaiCMRAjWw/: connect: no route to host
$ ./ffuf -ac -w words.txt -u https://notexisting.com/FUZZ
Error in autocalibration, exiting: Get https://notexisting.com/adminXVlBzgbaiCMRAjWw/: connect: no route to host

Adding the seed as in the PR.
$ vi pkg/ffuf/util.go
$ go build
$ ./ffuf -ac -w words.txt -u https://notexisting.com/FUZZ
Error in autocalibration, exiting: Get https://notexisting.com/adminPFpLgfKsynySawSo/: connect: no route to host

@joohoi
Copy link
Member

joohoi commented Jul 13, 2020

Good catch! You are right.

The autocalibration happens before job.Start(). Perhaps a good place to do the random seed initialization would be

ffuf/main.go

Line 166 in 7ffd74d

func prepareJob(conf *ffuf.Config) (*ffuf.Job, error) {
or just main(). I think the initialization in job.Start() should still stay, as the job runner can be used from external packages as well.

@bjhulst
Copy link
Contributor Author

bjhulst commented Jul 13, 2020

I did some profiling on the amount of seed updates done when using this code from the PR. The code only calls the "seed update inside the RandomString function" 4 times per execution of the ffuf command.

I think this current PR code will not harm performance and is cleaner to understand when the rand.Seed + rand.Intn are inside the same function block. :)

@joohoi
Copy link
Member

joohoi commented Jul 13, 2020

I agree that with the current functionality it's not big of an issue. However I think that seeding the random every time a random value is needed is kind of an antipattern, and would have to be changed around whenever the function gets more use. Because of this I think it'd be better to try and find the proper place to do the random seeding.

@bjhulst
Copy link
Contributor Author

bjhulst commented Jul 13, 2020

How about updating the rand.Seed after https://github.com/ffuf/ffuf/blob/master/pkg/ffuf/job.go#L333 ?

bjhulst added 2 commits July 13, 2020 13:36
rand.Seed updated just before usage
@bjhulst bjhulst changed the title Update util.go Update random seed logic Jul 13, 2020
@bjhulst
Copy link
Contributor Author

bjhulst commented Jul 16, 2020

Is this good to go?

Copy link
Member

@joohoi joohoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a changelog entry to denote that this has been fixed? Otherwise, it's good to go!

@bjhulst
Copy link
Contributor Author

bjhulst commented Jul 23, 2020

CHANGELOG.md updated.

Copy link
Member

@joohoi joohoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to go, thanks!

@joohoi joohoi merged commit 9bb6130 into ffuf:master Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants