-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbreak.php
166 lines (130 loc) · 5.42 KB
/
break.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
163
164
165
166
<?php
$TITLE_break = "Fixing WordPress 101";
// If a post req is made to break
if ($_POST['break']){
//// These lines get the database connection strings to be used in the following queries
$tableprefix ='$table_prefix';
$database = shell_exec("grep DB_NAME wp-config.php | cut -d \' -f4");
$user = shell_exec("grep DB_USER wp-config.php | cut -d \' -f4");
$password = shell_exec("grep DB_PASSWORD wp-config.php | cut -d\' -f4;");
$host = shell_exec("grep DB_HOST wp-config.php | cut -d\' -f4;");
$prefix = shell_exec("grep '$tableprefix' wp-config.php | cut -d\' -f2;");
// echo "
// db >>> $database <<<
// usr >>> $user <<<
// pw >>> $password <<<
// host >>> $host <<<
// prefix >>> $prefix <<<
// ";
/**** RIP wp-config.php *****/
function break_wp_config($data) {
if (stristr($data, 'DB_NAME')) {
$replace = 'define(\'DB_NAME\', \'notarealdatabase\'); ';
return $replace;
}
elseif (stristr($data, 'DB_USER')) {
$replace = 'define(\'DB_USER\', \'notyouruser\'); ';
return $replace;
}
elseif (stristr($data, 'DB_PASSWORD')) {
$replace = 'define(\'DB_PASSWORD\', \'notyourpassword\'); ';
return $replace;
}
elseif (stristr($data, 'DB_HOST')) {
$replace = 'define(\'DB_HOST\', \'notyourhost\'); ';
return $replace;
}
else{ return $data;}
}
// This section reads the wp-config.php file and passes it to the break_wp_config() function
$data = file('wp-config.php');
$data = array_map('break_wp_config',$data);
file_put_contents('wp-config.php', implode('', $data));
/**** END RIP wp-config.php *****/
/* Connect tot the sqldb and fuck it up
* These queries set the home and site url to http://google.com and the template and stylesheet to twentyfifteen and changes the users password
*/
$con= mysqli_connect('db:3306' ,'wordpress' ,'wordpress' , 'wordpress');
if (!$con) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
// $options = $prefix.'options';
// $users = $prefix.'users';
$options = 'wp_options';
$users = 'wp_users';
$query1 = "UPDATE `$options` SET `option_value` = 'http://google.com' WHERE `option_name` ='siteurl';";
$query2 = "UPDATE `$options` SET `option_value` = 'http://google.com' WHERE `option_name` ='home';";
$query3 = "UPDATE `$options` SET `option_value` = 'twentyfifteeen' WHERE `option_name` ='template';";
$query4 = "UPDATE `$options` SET `option_value` = 'twentyfifteeen' WHERE `option_name` ='stylesheet';";
// echo "
// db >>> $query1 <<<
// usr >>> $query2 <<<
// pw >>> $query3 <<<
// host >>> $query4 <<<
// ";
$result1 = mysqli_query($con, $query1);
$result2 = mysqli_query($con, $query2);
$result2 = mysqli_query($con, $query3);
$result2 = mysqli_query($con, $query4);
mysqli_close($con);
echo '<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><title>'.$TITLE_break.'</title></head>
<div style="text-align: center">
<div >
<h1 >'.$TITLE_break.'</h1>
</div>
<p> Your WordPress site has been broken!</p>
<p> Click continue to begin </p>
<form id="get-started" method="post" action='.$file.'>
<input name="start" value="start" style="display: none;"></input>
<input type="submit" value="Continue" class="btn" style=\'
background-color: #008A32;
color: white;
border-color: #008A32;
border-style: none;
height:5em;
width: 5em;\'></input>
</form>
';
/****** END DB ********/
$file=basename($_SERVER['PHP_SELF']);
}
elseif ($_POST['start']){
$url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$file=basename($_SERVER['PHP_SELF']);
$newurl= str_replace($file,'',$url);
header('Location:'.$newurl);
// unlink($file);
}
else{
$file=basename($_SERVER['PHP_SELF']);
echo '<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><title> '.$TITLE_break.' </title></head>
<div style="text-align: center">
<div style=\'background-color: black; color:red; width:100%; height: 50px;\'>
<h1 style="position: relative; top: 5px;">'.$TITLE_break.'</h1>
</div>
<p style="font-size: 24px; margin-left: 100px; margin-right:100px">
This activity is designed to test your critical thinking & troubleshooting skills. It is will also teach you the value of source control via git as well as the advantages of using docker. This course will not teach you to be a WordPress expert. But how to troubleshooting and fix a large majority of WordPress issues.
</p>
<br>
<p>
To complete this activity, you must fix the website.
</p>
<p style="font-size: 20px;"> Click continue to break your site </p>
<form id="get-started" method="post" action='.$file.'>
<input name="break" value="break" style="display: none;"></input>
<input type="submit" value="BREAK IT !" style=\'background-color: red; color: white; border-color: #008A32; border-style: none; height:5em; width: 25em;\'></input>
</form>
';
}
?>