-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConfig.cpp
More file actions
executable file
·212 lines (183 loc) · 4.58 KB
/
Copy pathConfig.cpp
File metadata and controls
executable file
·212 lines (183 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "Config.h"
#include "CJsonObject.hpp"
#include <iostream>
#include "BinaryEditor.h"
using namespace neb;
class JsonWrapper
{
public:
JsonWrapper(const std::string & str):_obj(str)
{
}
~JsonWrapper()
{
}
CJsonObject & get()
{
return _obj;
}
private:
CJsonObject _obj;
};
Config::Config():_json(0)
{
}
Config::~Config()
{
delete _json;
_json = nullptr;
}
std::string Config::getLibcAttrString(const std::string & k) const
{
std::string str;
_json->get()["libcdb"][_platform].Get(k, str);
return str;
}
uint64_t Config::getLibcAttrInt(const std::string & k) const
{
uint64 val = 0;
_json->get()["libcdb"][_platform].Get(k, val);
return val;
}
bool Config::isPolicyEnabled(const std::string & name) const
{
int val = 0;
_json->get()["policys"][name].Get("enable", val);
return val != 0;
}
bool Config::isProviderEnabled(const std::string & providerName) const
{
int val = 0;
_json->get()["codeProvider"][providerName].Get("enable", val);
return val != 0;
}
bool Config::isProviderActionEnabled(const std::string & providerName, const std::string & action) const
{
int val = 0;
_json->get()["codeProvider"][providerName][action].Get("enable", val);
return val != 0;
}
std::string Config::getGlobalMaxFastValue() const
{
std::string val;
_json->get()["codeProvider"]["ModifyLibcCodeProvider"]["modifyGlobalMaxFast"].Get("value", val);
return val;
}
void Config::getFmtPatchConfig(std::map<uint64_t, std::string> & patchConfig)
{
CJsonObject & fmtPolicy = _json->get()["policys"]["FmtVulScanRepairPolicy"]["patch"];
int size = fmtPolicy.GetArraySize();
for (int i = 0; i < size; ++i)
{
CJsonObject obj;
if (fmtPolicy.Get(i, obj))
{
std::string function, addr;
obj.Get("function", function);
obj.Get("callAddress", addr);
if (addr.empty() || function.empty())
{
continue;
}
uint64_t hexAddr = std::stoul(addr, nullptr, 16);
patchConfig[hexAddr] = function;
}
}
}
Config * Config::_instance = nullptr;
Config * Config::instance()
{
if (_instance == nullptr)
{
_instance = new Config;
}
return _instance;
}
void Config::destroy()
{
delete _instance;
_instance = nullptr;
}
void Config::init(const std::string & filename)
{
if(_json != nullptr)
return;
FILE * fp = fopen(filename.c_str(), "r");
if (fp)
{
fseek(fp, 0, SEEK_END);
long length = ftell(fp);
char * buff = new char[length];
fseek(fp, 0, SEEK_SET);
fread(buff, length, 1, fp);
fclose(fp);
_json = new JsonWrapper(buff);
if (BinaryEditor::instance()->getPlatform() == ELF_CLASS::ELFCLASS64)
{
_platform = "x64";
}
else
{
_platform = "x32";
}
}
else
{
std::cerr << "config.ini not found" << std::endl;
}
}
uint16_t Config::getBindShellPort()const
{
uint32_t val;
_json->get()["codeProvider"]["BindShellCodeProvider"].Get("port", val);
return (uint16_t)val;
}
std::string Config::getBindShellPasswd()const
{
std::string val;
_json->get()["codeProvider"]["BindShellCodeProvider"].Get("password", val);
return val;
}
std::string Config::getCaptureForwardPort()const
{
uint32_t port;
_json->get()["codeProvider"]["Capture01CodeProvider"].Get("forward_port", port);
char buf[255] = {0};
uint8_t s1 = (port & 0x0000ff00)>>8;
uint8_t s2 = (port & 0xff);
snprintf(buf, sizeof(buf), "%02x%02x", s2, s1);
return buf;
}
void Config::getRiseStackFunc(std::set<uint64_t> & funcs) const
{
CJsonObject & obj = _json->get()["policys"]["RiseStackPolicy"]["functions"];
int size = obj.GetArraySize();
std::cout << "size :" << size << std::endl;
for (int i = 0; i < size; ++i)
{
std::string function;
if (obj.Get(i, function))
{
std::cout << "Func :" << function << std::endl;
funcs.insert(std::strtoul(function.c_str(), nullptr, 16));
}
}
}
std::string Config::getCaptureForwardHost()const
{
std::string val;
_json->get()["codeProvider"]["Capture01CodeProvider"].Get("forward_host", val);
std::string::size_type pos1 = val.find('.');
uint8_t s1 = (uint8_t)std::stoul(val.substr(0, pos1));
std::string::size_type pos2 = val.find('.', pos1 + 1);
uint8_t s2 = (uint8_t)std::stoul(val.substr(pos1 + 1, pos2 - pos1));
pos1 = pos2;
pos2 = val.find('.', pos1 + 1);
uint8_t s3 = (uint8_t)std::stoul(val.substr(pos1 + 1, pos2 - pos1));
pos1 = pos2;
pos2 = val.find('.', pos1 + 1);
uint8_t s4 = (uint8_t)std::stoul(val.substr(pos1 + 1, pos2 - pos1));
char buf[255] = {0};
snprintf(buf, sizeof(buf), "%02x%02x%02x%02x", s4,s3,s2,s1);
return buf;
}