-
Notifications
You must be signed in to change notification settings - Fork 128
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
Add Support for fuzzing by attaching to running processes on Windows. #38
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,13 @@ void Fuzzer::ParseOptions(int argc, char **argv) { | |
incremental_coverage = GetBinaryOption("-incremental_coverage", argc, argv, true); | ||
|
||
add_all_inputs = GetBinaryOption("-add_all_inputs", argc, argv, false); | ||
|
||
process_name = GetOption("-process_name", argc, argv); | ||
ifratric marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (process_name != NULL) { | ||
//set threads to one as multiple threads attaching to one process does not work well | ||
num_threads = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps if |
||
} | ||
} | ||
|
||
void Fuzzer::SetupDirectories() { | ||
|
@@ -245,8 +252,8 @@ RunResult Fuzzer::RunSampleAndGetCoverage(ThreadContext *tc, Sample *sample, Cov | |
FATAL("Repeatedly failed to deliver sample"); | ||
} | ||
} | ||
|
||
RunResult result = tc->instrumentation->Run(tc->target_argc, tc->target_argv, init_timeout, timeout); | ||
|
||
tc->instrumentation->GetCoverage(*coverage, true); | ||
|
||
// save crashes and hangs immediately when they are detected | ||
|
@@ -325,8 +332,9 @@ RunResult Fuzzer::TryReproduceCrash(ThreadContext* tc, Sample* sample, uint32_t | |
FATAL("Repeatedly failed to deliver sample"); | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some changes to spacing that should be reverted. |
||
result = tc->instrumentation->RunWithCrashAnalysis(tc->target_argc, tc->target_argv, init_timeout, timeout); | ||
|
||
tc->instrumentation->ClearCoverage(); | ||
|
||
if (result == CRASH) return result; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ class Instrumentation { | |
virtual RunResult RunWithCrashAnalysis(int argc, char** argv, uint32_t init_timeout, uint32_t timeout) { | ||
return Run(argc, argv, init_timeout, timeout); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary changes to spacing |
||
virtual void CleanTarget() = 0; | ||
|
||
virtual bool HasNewCoverage() = 0; | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -22,13 +22,19 @@ limitations under the License. | |||
|
||||
#include <sstream> | ||||
|
||||
|
||||
void TinyInstInstrumentation::Init(int argc, char **argv) { | ||||
instrumentation = new LiteCov(); | ||||
instrumentation->Init(argc, argv); | ||||
|
||||
persist = GetBinaryOption("-persist", argc, argv, false); | ||||
num_iterations = GetIntOption("-iterations", argc, argv, 1); | ||||
process_name = GetOption("-process_name", argc, argv); | ||||
script = ArgvToCmd(argc, argv); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running a script is a part of sample delivery so I don't think it should go in this class. Instead, my proposal is to
|
||||
|
||||
attach_mode = false; | ||||
if(process_name != NULL) { | ||||
attach_mode = true; | ||||
} | ||||
} | ||||
|
||||
RunResult TinyInstInstrumentation::Run(int argc, char **argv, uint32_t init_timeout, uint32_t timeout) { | ||||
|
@@ -68,7 +74,17 @@ RunResult TinyInstInstrumentation::Run(int argc, char **argv, uint32_t init_time | |||
WARN("Target function not reached, retrying with a clean process\n"); | ||||
instrumentation->Kill(); | ||||
cur_iteration = 0; | ||||
status = instrumentation->Run(argc, argv, init_timeout); | ||||
if (attach_mode) { | ||||
Sleep(init_timeout); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sleep is a Windows function, see e.g. Line 202 in 6134ff1
|
||||
processID = FindProcessId(process_name); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a check here if FindProcessId failed. Instead of calling
|
||||
if (script != NULL) { | ||||
HANDLE thread_handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)system, script, 0, NULL); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 667 in 46c1c9b
|
||||
CloseHandle(thread_handle); | ||||
} | ||||
status = instrumentation->Attach(processID, timeout1); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here in attach mode you call |
||||
} else { | ||||
status = instrumentation->Run(argc, argv, init_timeout); | ||||
} | ||||
} | ||||
|
||||
if (status != DEBUGGER_TARGET_START) { | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ class TinyInstInstrumentation : public Instrumentation { | |
|
||
RunResult Run(int argc, char** argv, uint32_t init_timeout, uint32_t timeout) override; | ||
RunResult RunWithCrashAnalysis(int argc, char** argv, uint32_t init_timeout, uint32_t timeout) override; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary changes to spacing. |
||
void CleanTarget() override; | ||
|
||
bool HasNewCoverage() override; | ||
|
@@ -47,6 +47,10 @@ class TinyInstInstrumentation : public Instrumentation { | |
protected: | ||
LiteCov * instrumentation; | ||
bool persist; | ||
boolean attach_mode; | ||
int processID; | ||
char * process_name; | ||
char * script; | ||
int num_iterations; | ||
int cur_iteration; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure windows services is a good example here as afaik all windows services run under the same process name (
svchost.exe
)