-
Notifications
You must be signed in to change notification settings - Fork 7
/
manual_query.php
162 lines (146 loc) · 7.25 KB
/
manual_query.php
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
<?php
// Dipake gara2 gabisa pake adminer karena web target ada masalah gabisa simpen session mysql
// error_reporting(0);
$db_host = "";
$db_user = "";
$db_pass = "";
// Current url
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$CurPageURL = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
// Show tables
$params = $_GET;
$params['query'] = 'show tables';
$query_result = http_build_query($params);
?>
<!DOCTYPE html>
<html>
<head>
<title>._.</title>
<link rel="stylesheet" href="https://hackcss.egoist.dev/hack.css">
<link rel="stylesheet" href="https://hackcss.egoist.dev/dark.css">
</head>
<body class="hack dark">
<div class="main container" style="padding-top: 3em;">
<pre style="display: flex; justify-content: center; border:none;"> /\_/\
( o.o )
> ^ <
Manuaaal Query</pre>
<p style="text-align: center;margin-bottom: 2rem;padding-bottom: 1rem;border-bottom: 1px dotted #ffffff;">
Menu:
<a href="<?= parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH) ?>">Show Databases</a>
<?php
if (isset($_GET['db']) && !empty($_GET['db'])) {
echo '- <a href="' . $_SERVER['PHP_SELF'] . '?' . $query_result . '">Show Tables</a>';
}
?>
</p>
<div class="grid" style="margin-bottom: 10px;margin-top: 5em;">
<div class="cell -12of12">
<h2>Query</h2>
<form method="GET" class="form" action="">
<fieldset class="form-group">
<label for="nama">DB:</label>
<input id="nama" type="text" name="db" value="<?= isset($_GET['db']) ? $_GET['db'] : '' ?>" class="form-control">
</fieldset>
<fieldset class="form-group">
<label for="nama">Query:</label>
<input id="nama" type="text" name="query" value="<?= isset($_GET['query']) ? $_GET['query'] : '' ?>" class="form-control">
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary btn-block">Run</button>
</div>
</form>
</div>
</div>
<div class="grid">
<div class="cell -12of12" style="max-width:100%;overflow-x: auto;">
<h2>Output | <a href="#" onclick="return copyClipboard()">Copy to Clipboard</a></h2>
<pre style="padding: 1em; border: 1px dotted #fff;" id="asd"><?php
if (!isset($_GET['db'])) {
$mysqli = new mysqli($db_host, $db_user, $db_pass);
if ($mysqli->connect_errno) {
trigger_error('query failed: '.$mysqli->connect_error, E_USER_ERROR);
}
$result = $mysqli->query('SHOW databases')
or trigger_error('connect failed: '.join(',', $mysqli->error_list), E_USER_ERROR);
$rr = '';
echo 'Databases ('.$result->num_rows.'):<br/>';
foreach( $result as $row ) {
$r = array_shift($row);
$r = htmlentities($r);
echo " <a href='".$CurPageURL."?db=".$r."'>set</a> " . $r;
echo "<br/>";
$rr .= $r."\r\n";
}
echo '<textarea style="display:none;" id="output">'.$rr.'</textarea>';
echo "</div></body></html>";
} else {
$db = $_GET['db'];
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db);
if ($mysqli->connect_errno) {
trigger_error('query failed: '.$mysqli->connect_error, E_USER_ERROR);
}
if (empty($_GET['query'])) {
$_GET['query'] = "show tables";
}
$result = $mysqli->query($_GET['query'])
or trigger_error('connect failed: '.join(',', $mysqli->error_list), E_USER_ERROR);
$out = [];
$rr = '';
if (is_bool($result)) {
if ($result) {echo 'True';} else {echo 'False';}
} elseif (is_object($result)) {
foreach( $result as $key => $row ) {
if (count($row) <= 1) {
$r = array_shift($row);
if (strtolower($_GET['query']) == "show tables") {
if ($key < 1) {
echo 'Tables ('.$result->num_rows.'):<br/>';
}
$params = $_GET;
$params['query'] = 'select * from ' . $r . ' limit 10';
$query_result = http_build_query($params);
echo '<a href="' . $_SERVER['PHP_SELF'] . '?' . $query_result . '">select</a> ' . htmlentities($r);
$rr .= htmlentities($r)."\r\n";
} else {
echo htmlentities($r);
}
echo '<br/>';
} else {
$out[] = $row;
}
}
if (count($out) != 0) {
$out_json = htmlentities(json_encode($out, JSON_PRETTY_PRINT));
print_r($out_json);
print_r('<textarea style="display:none;" id="output">'.$out_json.'</textarea>');
} else {
print_r('<textarea style="display:none;" id="output">'.$rr.'</textarea>');
}
}
}
?>
</pre>
</div>
</div>
</div>
<?php
if (isset($_GET['db'])) {
echo '<script>
ambil = document.getElementById("asd").innerHTML;
result = ambil.trim();
document.getElementById("asd").innerHTML = result;
</script>';
}
?>
<script>
function copyClipboard() {
var copyText = document.getElementById("output");
copyText.select();
copyText.setSelectionRange(0, 99999); // For mobile devices
navigator.clipboard.writeText(copyText.value);
return new Promise((resolve) => setTimeout(resolve, 1000));
}
</script>
</body>
</html>