Skip to content

Commit cccf5b3

Browse files
committed
Add extra functions to check in fpva plugin
1 parent 4ed7175 commit cccf5b3

File tree

3 files changed

+72
-7
lines changed

3 files changed

+72
-7
lines changed

user_agent/fpva/fpva.C

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Fpva::Fpva() {
1515
// Each checker is called for each point
1616
checkers_.push_back(new ForkChecker(mgr_));
1717
checkers_.push_back(new IpcChecker(mgr_));
18+
checkers_.push_back(new FileChecker(mgr_));
19+
checkers_.push_back(new PrivilegeChecker(mgr_));
1820
}
1921

2022
Fpva::~Fpva() {

user_agent/fpva/fpva_checker.C

+51-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ bool ForkChecker::PreCheck(sp::SpPoint* pt, sp::SpFunction* callee) {
126126
bool ForkChecker::PostCheck(sp::PointCallHandle* pHandle) {
127127
sp::SpFunction* callee = pHandle->GetCallee();
128128
if (callee->name().compare("fork") == 0) {
129-
pid_t ret = (pid_t) pHandle->GetReturnValue();
129+
pid_t ret = (pid_t)pHandle->GetReturnValue();
130130
if (ret == 0) {
131131
mgr_->NewDoc();
132132
} else {
@@ -144,4 +144,53 @@ bool ForkChecker::PostCheck(sp::PointCallHandle* pHandle) {
144144
return true;
145145
}
146146

147-
} // namespace mist
147+
bool FileChecker::PreCheck(sp::SpPoint* pt, sp::SpFunction* callee) {
148+
if (callee->name() == "open" || callee->name() == "fopen") {
149+
sp::ArgumentHandle h;
150+
char** fname = (char**)PopArgument(pt, &h, sizeof(void*));
151+
CallTrace newTrace;
152+
newTrace.functionName = callee->name();
153+
newTrace.timeStamp = std::to_string(FpvaUtils::GetUsec());
154+
newTrace.parameters.insert(
155+
std::pair<std::string, std::string>("file", std::string(*fname)));
156+
mgr_->AddTrace(&newTrace);
157+
return true;
158+
} else if (callee->name() == "chmod") {
159+
sp::ArgumentHandle h;
160+
char** fname = (char**)PopArgument(pt, &h, sizeof(void*));
161+
mode_t* mode = (mode_t*)PopArgument(pt, &h, sizeof(mode_t));
162+
CallTrace newTrace;
163+
newTrace.functionName = callee->name();
164+
newTrace.timeStamp = std::to_string(FpvaUtils::GetUsec());
165+
newTrace.parameters.insert(
166+
std::pair<std::string, std::string>("file", std::string(*fname)));
167+
newTrace.parameters.insert(
168+
std::pair<std::string, std::string>("mode", std::to_string(*mode)));
169+
mgr_->AddTrace(&newTrace);
170+
return true;
171+
}
172+
return false;
173+
}
174+
175+
bool FileChecker::PostCheck(sp::PointCallHandle*) { return true; }
176+
177+
bool PrivilegeChecker::PreCheck(sp::SpPoint* pt, sp::SpFunction* callee) {
178+
if (callee->name() == "seteuid" || callee->name() == "setuid") {
179+
sp::ArgumentHandle h;
180+
uid_t* uid = (uid_t*)PopArgument(pt, &h, sizeof(uid_t));
181+
CallTrace newTrace;
182+
newTrace.functionName = callee->name();
183+
newTrace.timeStamp = std::to_string(FpvaUtils::GetUsec());
184+
newTrace.parameters.insert(std::pair<std::string, std::string>(
185+
"name", FpvaUtils::GetUserName(*uid)));
186+
newTrace.parameters.insert(
187+
std::pair<std::string, std::string>("uid", std::to_string(*uid)));
188+
mgr_->AddTrace(&newTrace);
189+
return true;
190+
}
191+
return false;
192+
}
193+
194+
bool PrivilegeChecker::PostCheck(sp::PointCallHandle*) { return true; }
195+
196+
} // namespace fpva

user_agent/fpva/fpva_checker.h

+19-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class FpvaChecker {
3838
class ProcInitChecker : public OneTimeChecker {
3939
public:
4040
using OneTimeChecker::OneTimeChecker;
41-
virtual bool Run();
41+
bool Run();
4242
~ProcInitChecker() {}
4343
};
4444

@@ -47,8 +47,8 @@ class IpcChecker : public FpvaChecker {
4747
public:
4848
using FpvaChecker::FpvaChecker;
4949
virtual ~IpcChecker() {}
50-
virtual bool PreCheck(sp::SpPoint* pt, sp::SpFunction* callee);
51-
virtual bool PostCheck(sp::PointCallHandle* pHandle);
50+
bool PreCheck(sp::SpPoint* pt, sp::SpFunction* callee);
51+
bool PostCheck(sp::PointCallHandle* pHandle);
5252

5353
protected:
5454
string port;
@@ -57,8 +57,22 @@ class IpcChecker : public FpvaChecker {
5757
class ForkChecker : public FpvaChecker {
5858
public:
5959
using FpvaChecker::FpvaChecker;
60-
virtual bool PreCheck(sp::SpPoint* pt, sp::SpFunction* callee);
61-
virtual bool PostCheck(sp::PointCallHandle* pHandle);
60+
bool PreCheck(sp::SpPoint* pt, sp::SpFunction* callee);
61+
bool PostCheck(sp::PointCallHandle* pHandle);
62+
};
63+
64+
class FileChecker : public FpvaChecker {
65+
public:
66+
using FpvaChecker::FpvaChecker;
67+
bool PreCheck(sp::SpPoint* pt, sp::SpFunction* callee);
68+
bool PostCheck(sp::PointCallHandle* pHandle);
69+
};
70+
71+
class PrivilegeChecker : public FpvaChecker {
72+
public:
73+
using FpvaChecker::FpvaChecker;
74+
bool PreCheck(sp::SpPoint* pt, sp::SpFunction* callee);
75+
bool PostCheck(sp::PointCallHandle* pHandle);
6276
};
6377

6478
} // namespace fpva

0 commit comments

Comments
 (0)