-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexploits.php
More file actions
355 lines (307 loc) · 13.2 KB
/
exploits.php
File metadata and controls
355 lines (307 loc) · 13.2 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<?php
include('inc/lib.inc');
include('header.php');
require_once('phplib/exploits.inc');
check_view_perms();
$f = new exploitsform;
if ($WithSelected) {
check_edit_perms();
switch ($WithSelected) {
case "Delete":
if (array_search('exploits',$_ENV['no_edit'])) {
echo "No Delete Allowed";
} else {
$sql = "DELETE FROM exploits WHERE id IN (";
$sql .= implode(",",$id);
$sql .= ")";
if ($dev) echo "<h1>$sql</h1>";
$db->query($sql);
echo $db->affected_rows()." deleted.";
}
if (!$dev) echo "<META HTTP-EQUIV=REFRESH CONTENT=\"10; URL=".$sess->self_url()."\">";
break;
case "Print";
foreach ($id as $row) {
echo "<div class='float_left'>\n";
$f = new exploitsform;
$f->find_values($row);
$f->freeze();
$f->display();
echo "\n</div>\n";
}
echo "\n<br style='clear: both;'>\n";
break;
}
echo " <a href=\"".$sess->self_url();
echo "\">Back to exploits.</a><br>\n";
page_close();
exit;
}
if ($submit) {
switch ($submit) {
case "Copy": $id="";
case "Save":
if ($id) $submit = "Edit";
else $submit = "Add";
case "Add":
case "Edit":
if (isset($auth)) {
check_edit_perms();
if (!$f->validate()) {
$cmd = $submit;
echo "<font class='bigTextBold'>$cmd Exploits</font>\n";
$f->reload_values();
$f->display();
page_close();
exit;
}
else
{
echo "Saving....";
$id = $f->save_values();
echo "<b>Done!</b><br />\n";
if (!$dev) echo "<META HTTP-EQUIV=REFRESH CONTENT=\"2; URL=".$sess->self_url()."\">";
echo " <a href=\"".$sess->self_url()."\">Back to exploits.</a><br />\n";
page_close();
exit;
}
} else {
echo "You are not logged in....";
echo "<b>Aborted!</b><br />\n";
}
case "View":
case "Back":
echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL=".$sess->self_url()."\">";
echo " <a href=\"".$sess->self_url()."\">Back to exploits.</a><br />\n";
page_close();
exit;
case "Delete":
if (isset($auth)) {
check_edit_perms();
echo "Deleting....";
$f->save_values();
echo "<b>Done!</b><br />\n";
} else {
echo "You are not logged in....";
echo "<b>Aborted!</b><br />\n";
}
if (!$dev) echo "<META HTTP-EQUIV=REFRESH CONTENT=\"2; URL=".$sess->self_url()."\">";
echo " <a href=\"".$sess->self_url()."\">Back to exploits.</a><br />\n";
page_close();
exit;
default:
include("search.php");
}
} else {
if ($id) {
$f->find_values($id);
} else {
include("search.php");
}
}
if ($export_results) $f->setup();
else $f->javascript();
switch ($cmd) {
case "View":
case "Delete":
$f->freeze();
case "Add":
case "Copy":
if ($cmd=="Copy") $id="";
case "Edit":
echo "<font class='bigTextBold'>$cmd Known Exploits Attempted on our servers</font>\n";
$f->display();
if ($orig_cmd=="View") $f->showChildRecords();
break;
default:
$cmd="Query";
$t = new exploitsTable;
$t->heading = 'on';
$t->sortable = 'on';
$t->trust_the_data = false; /* if true, send raw data without htmlspecialchars */
$t->limit = 100; /* max length of field data before trucation and add ... */
$t->add_extra = 'on'; /* or set to base url of php file to link to, defaults to PHP_SELF */
# $t->add_extra = "SomeFile.php"; # use defaults, but point to a different target file.
# $t->add_extra = array("View","Edit","Copy","Delete"); # just specify the command names.
# $t->add_extra = array( # or specify parameters as well.
# "View" => array("target"=>"PayPal.php","key"=>"id","perm"=>"admin","display"=>"view","class"=>"ae_view"),
# );
$t->add_total = 'on'; /* add a grand total row to the bottom of the table on the numberic columns */
$t->add_insert = $f->classname; /* Add a blank row ontop of table allowing insert or search */
$t->add_insert_buttons = 'Search'; /* Control which buttons appear on the add_insert row eg: Add,Search */
/* See below - EditMode can also be turned on/off by user if section below uncommented */
#$t->edit = $f->classname; /* Allow rows to be editable with a save button that appears onchange */
#$t->ipe_table = 'exploits'; /* Make in place editing changes immediate without a save button */
#$t->checkbox_menu = Array('Print');
#$t->check = 'id'; /* Display a column of checkboxes with value of key field*/
$db = new DB_probind;
if (!$export_results) echo "<a href=\"".$sess->self_url().$sess->add_query(array("cmd"=>"Add"))."\">Add</a> Exploits\n";
if (array_key_exists("exploits_fields",$_REQUEST)) $exploits_fields = $_REQUEST["exploits_fields"];
if (empty($exploits_fields)) {
$exploits_fields = array_first_chunk($t->default,8,11);
$sess->register("exploits_fields");
}
if (in_array(@$LocField,$exploits_fields)) displayLocSelect($f->classname,$LocField);
$t->fields = $exploits_fields;
#$t->extra_html = array('fieldname'=>'extrahtml');
#$t->align = array('fieldname'=>'right', 'otherfield'=>'center');
if (!$export_results) {
echo "Export to ";
echo " <input name='ExportTo' type=radio onclick=\"javascript:export_results('Excel2007');\">Excel 2007";
echo "<br>";
echo "<a href=javascript:show('ColumnSelector')>Column Chooser</a> ";
echo "<form id=ColumnSelector method='post' style=display:none>\n";
echo "<a href=javascript:hide('ColumnSelector')>Hide</a>";
echo " Columns: <br />";
foreach ($t->all_fields as $field) {
if (in_array($field,$exploits_fields,TRUE)) $chk = "checked='checked'"; else $chk="";
echo "\n<input type='checkbox' $chk name=exploits_fields[] value='$field' />$field <br />";
}
echo "\n<input type=submit name=setcols value='Set' />";
if ($sess->have_edit_perm()) {
if ($EditMode=='on') {
$on='checked="checked"'; $off='';
$t->edit = 'exploitsform';
# $t->ipe_table = 'exploits'; #uncomment this for immediate table update (no save button)
} else {
$off='checked="checked"'; $on='';
}
echo "\n<br />\nEdit Mode <input type='radio' name='EditMode' value='on' $on> On <input type='radio' name='EditMode' value='off' $off /> Off ";
} else {
$EditMode='';
}
echo "\n</form>\n";
}
// When we hit this page the first time,
// there is no $q.
if (!isset($q_exploits)) {
$q_exploits = new exploits_Sql_Query; // We make one
$q_exploits->conditions = 1; // ... with a single condition (at first)
$q_exploits->translate = "on"; // ... column names are to be translated
$q_exploits->container = "on"; // ... with a nice container table
$q_exploits->variable = "on"; // ... # of conditions is variable
$q_exploits->lang = "en"; // ... in English, please
$q_exploits->extra_cond = "";
$q_exploits->default_query = "1";
$q_exploits->default_sortorder = "id desc";
$sess->register("q_exploits"); // and don't forget this!
}
if ($rowcount) {
$q_exploits->start_row = $startingwith;
$q_exploits->row_count = $rowcount;
} else {
$startingwith = $q_exploits->start_row;
$rowcount = $q_exploits->row_count;
}
if ($submit=='Search') $query = $f->search(); // create sql query from form posted values.
// When we hit that page a second time, the array named
// by $base will be set and we must generate the $query.
// Ah, and don\'t set $base to "q" when $q is your Sql_Query
// object... :-)
if (array_key_exists("x",$_POST)) {
get_request_values("x");
$query = $q_exploits->where("x", 1);
$hideQuery = "";
} else {
$hideQuery = "style='display:none'";
}
if ($Format = $export_results) {
$custom_query = array_key_exists("custom_query",$_POST) ? $_POST["custom_query"] : "";
require_once "/usr/share/PHPExcel.php";
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory;
PHPExcel_Settings::setCacheStorageMethod($cacheMethod);
$locale = 'en_us';
$validLocale = PHPExcel_Settings::setLocale($locale);
$workbook = new PHPExcel();
$workbook->setActiveSheetIndex(0);
$worksheet1 = $workbook->getActiveSheet();
$worksheet1->setTitle('exploits');
$cols = count($t->fields);
$range = "A1:" . chr(64+$cols) . "1";
$worksheet1->getStyle($range)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB(PHPExcel_Style_Color::COLOR_DARKGREEN);
$worksheet1->getStyle($range)->getAlignment()->setHorizontal('center');
$worksheet1->getStyle($range)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
$r = 1;
$col = "A";
foreach ($t->fields as $field) {
if (!isset($f->form_data->elements[$field]["ob"])) {var_dump($f->form_data->elements[$field]); exit; }
$el = $f->form_data->elements[$field]["ob"];
if (!$size=@$el->size) {
$size = 5;
if (!isset($el->options)) {
$size = strlen($el->value);
} else
foreach($el->options as $option) {
if (is_array($option)) $len=strlen($option["label"]);
else $len = strlen($option);
if ($len>$size) $size = $len;
}
}
$worksheet1->getColumnDimension($col)->setWidth($size);
$worksheet1->getCell("$col$r")->setValue($t->map_cols[$field]);
$col++;
}
$sql = "SELECT * FROM exploits $custom_query WHERE $query";
$db->query($sql);
while ($db->next_record()) {
$r++;
$col = "A";
foreach ($t->fields as $field) {
$worksheet1->getCell("$col$r")->setValue($db->f($field));
$col++;
}
}
$ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
header("Content-Type: $ContentType");
header("Content-Disposition: attachment;filename=\"exploits.xlsx\"");
header("Cache-Control: max-age=0");
$objWriter = PHPExcel_IOFactory::createWriter($workbook, $Format);
$objWriter->save('php://output');
exit;
}
if (empty($sortorder)) $sortorder = empty($q_exploits->last_sortorder) ? $q_exploits->default_sortorder : $q_exploits->last_sortorder ;
if (empty($query)) $query = empty($q_exploits->last_query) ? $q_exploits->default_query : $q_exploits->last_query ;
$q_exploits->last_query = $query;
$q_exploits->last_sortorder = $sortorder;
/*
$db->query("SELECT COUNT(*) as total from ".$db->qi("exploits")." where ".$query);
$db->next_record();
if ($db->f("total") < ($q_exploits->start_row - $q_exploits->row_count))
{ $q_exploits->start_row = $db->f("total") - $q_exploits->row_count; }
*/
if ($q_exploits->start_row < 0) { $q_exploits->start_row = 0; }
# $f->sort_function_maps = array( /* use a function to sort values for specified fields */
# "ip_addr"=>"inet_aton",
# );
if (strpos(strtolower($query),"order by")===false) {
if ($so=$f->order_by($sortorder)) $query .= " order by ".$so;
}
$query .= " LIMIT ".$q_exploits->start_row.",".$q_exploits->row_count;
// In any case we must display that form now. Note that the
// "x" here and in the call to $q->where must match.
// Tag everything as a CSS "query" class.
echo "<a href=javascript:show('customQuery')>Custom Query</a>";
echo "\n<div id=customQuery $hideQuery><a href=javascript:hide('customQuery')>Hide</a>\n";
printf($q_exploits->form("x", $t->map_cols, "query"));
echo "\n</div>\n";
if (array_key_exists("more_0",$x)) {$query="";}
if (array_key_exists("less_0",$x)) {$query="";}
// Do we have a valid query string?
if ($query) {
// Do that query
$sql = $t->select($f).$query;
$db->query($sql);
#$db->query("select * from ".$db->qi("exploits")." where ". $query);
// Show that condition
echo "<a href=javascript:show('QueryStats')>Query Stats</a><div id=QueryStats style=display:none>";
echo "<a href=javascript:hide('QueryStats')>Hide</a><br>";
printf("Query Condition = %s<br />\n", $query);
printf("Query Results = %s<br /></div>\n", $db->num_rows());
echo "<br />";
// Dump the results (tagged as CSS class default)
$t->show_result($db, "default");
}
} // switch $cmd
page_close();
include('footer.php');
?>