[openresty]第三节:操作redis数据

同样的看redis组件

https://github.com/openresty/lua-resty-redis

按照实例添加redis.conf


worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8091;
location / {
default_type text/html;
content_by_lua_block {
local redis = require "resty.redis"
local red = redis:new()

red:set_timeout(1000)
local ok,err = red:connect("127.0.0.1", 6379)
if not ok then
ngx.say("fail to connent", err)
return
end

local res,err = red:get("lua")
if not res then
ngx.say("failed to get lua", err)
return
end
ngx.say(res)
}
}
}
}

启动redis.conf配置

../nginx/sbin/nginx -p `pwd`/ -c conf/redis.conf

访问localhost:8091 获取了key为lua的数据,使用起来非常简单。

[openresty]第二节:操作mysql数据库

openresty操作数据库本质上调用了lua-resty-mysql 组件

具体参照git:https://github.com/openresty/lua-resty-mysql#table-of-contents

同样的在/usr/local/openresty/work/conf/ 文件夹下添加新的文件mysql.conf

内容如下:


worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8089;
server_name localhost;
location / {
content_by_lua '
local arg = ngx.req.get_uri_args()
local mysql = require "resty.mysql"
local db, err = mysql:new()
if not db then
ngx.say("failed to instantiate mysql: ", err)
return
end

db:set_timeout(1000) -- 1 sec
local ok, err, errcode, sqlstate = db:connect{
host = "127.0.0.1",
port = 3306,
database = "test",
user = "xxxx",
password = "xxxxxxx",
max_packet_size = 1024 * 1024 }

if not ok then
ngx.say("failed to connect: ", err, ": ", errcode, " ", sqlstate)
return
end

--ngx.say("connected to mysql.")
local id = tonumber(arg.id)
queryStr = "select goods_id,goods_name from goods_test where goods_id ="..id
--ngx.say(queryStr)
res, err, errcode, sqlstate =
--db:query("select * from goods_test order by goods_id asc", 10)
db:query(queryStr)
if not res then
ngx.say("bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
return
end
local cjson = require "cjson"
ngx.say("result: ", cjson.encode(res))
';
}

}
}

是不是很简单,然后../nginx/sbin/nginx -p `pwd`/ -s reload -c conf/mysql.conf

重新加载配置文件,这样访问localhost:8089?id=1 就可以筛选数据库中主键ID=1的数据了。应该有mysql注入问题,所以参数全部转化为int类型,基本的网络安全意识不能没有。

 

[openresty]安装和入门(一)

首先推荐官网:http://openresty.org/en/

一,安装openresty包

1,安装依赖

yum install perl dos2unix

yum install pcre-devel openssl-devel gc-c++

wget https://openresty.org/download/openresty-1.11.2.1.tar.gz

解压tar zxvf openresty-1.11.2.1

./configure

gmake

gmake install

安装完成

默认的路径是/usr/local/openresty/

二 hello world 程序

参考http://openresty.org/cn/getting-started.html

Prepare directory layout

We first create a separate directory for our experiments. You can use an arbitrary directory. Here for simplicity, we just use~/work:

mkdir ~/work
cd ~/work
mkdir logs/ conf/

Note that we’ve also created the logs/ directory for logging files and conf/ for our config files.

Prepare the nginx.conf config file

Create a simple plain text file named conf/nginx.conf with the following contents in it:

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    server {
        listen 8088;
        location / {
            default_type text/html;
            content_by_lua '
                ngx.say("<p>hello, world</p>")
            ';
        }
    }
}

If you’re familiar with Nginx configuration, it should look very familiar to you. OpenResty is just an enhanced version of Nginxby means of addon modules anyway. You can take advantage of all the exisitng goodies in the Nginx world.

Start the Nginx server

Assuming you have installed OpenResty into/usr/local/openresty (this is the default)

Then we start the nginx server with our config file this way:
/usr/local/openresty/sbin/nginx -p `pwd`/ -c conf/nginx.conf

-p 标识的是

-p prefix : set prefix path (default: /usr/local/openresty/nginx/) 路径
-c filename : set configuration file (default: conf/nginx.conf)     配置

Error messages will go to the stderr device or the default error log files logs/error.log in the current working directory.

Access our HelloWorld web service

We can use curl to access our new web service that says HelloWorld:

curl http://localhost:8088/

If everything is okay, we should get the output

<p>hello, world</p>

ab 压测一下

ab -c 10 -n 100 http://localhost:8088/

在单核阿里云的配置下:

Requests per second:    240.93 [#/sec] (mean) 还算比较高的

未完待续。。。。

[SQL注入]使用sqlmap进行简单的mysql注入

最近使用了sqlmap进行了简单的操作。现在先说明sqlmap的一些参数:

  1. #HiRoot’s Blog
  2. Options(选项):
  3. –version 显示程序的版本号并退出
  4. -h, –help 显示此帮助消息并退出
  5. -v VERBOSE 详细级别:0-6(默认为1)
  6. Target(目标):
  7. 以下至少需要设置其中一个选项,设置目标URL。
  8. -d DIRECT 直接连接到数据库。
  9. -u URL, –url=URL 目标URL。
  10. -l LIST 从Burp或WebScarab代理的日志中解析目标。
  11. -r REQUESTFILE 从一个文件中载入HTTP请求。
  12. -g GOOGLEDORK 处理Google dork的结果作为目标URL。
  13. -c CONFIGFILE 从INI配置文件中加载选项。
  14. Request(请求):
  15. 这些选项可以用来指定如何连接到目标URL。
  16. –data=DATA 通过POST发送的数据字符串
  17. –cookie=COOKIE HTTP Cookie头
  18. –cookie-urlencode URL 编码生成的cookie注入
  19. –drop-set-cookie 忽略响应的Set – Cookie头信息
  20. –user-agent=AGENT 指定 HTTP User – Agent头
  21. –random-agent 使用随机选定的HTTP User – Agent头
  22. –referer=REFERER 指定 HTTP Referer头
  23. –headers=HEADERS 换行分开,加入其他的HTTP头
  24. –auth-type=ATYPE HTTP身份验证类型(基本,摘要或NTLM)(Basic, Digest or NTLM)
  25. –auth-cred=ACRED HTTP身份验证凭据(用户名:密码)
  26. –auth-cert=ACERT HTTP认证证书(key_file,cert_file)
  27. –proxy=PROXY 使用HTTP代理连接到目标URL
  28. –proxy-cred=PCRED HTTP代理身份验证凭据(用户名:密码)
  29. –ignore-proxy 忽略系统默认的HTTP代理
  30. –delay=DELAY 在每个HTTP请求之间的延迟时间,单位为秒
  31. –timeout=TIMEOUT 等待连接超时的时间(默认为30秒)
  32. –retries=RETRIES 连接超时后重新连接的时间(默认3)
  33. –scope=SCOPE 从所提供的代理日志中过滤器目标的正则表达式
  34. –safe-url=SAFURL 在测试过程中经常访问的url地址
  35. –safe-freq=SAFREQ 两次访问之间测试请求,给出安全的URL
  36. Optimization(优化):
  37. 这些选项可用于优化SqlMap的性能。
  38. -o 开启所有优化开关
  39. –predict-output 预测常见的查询输出
  40. –keep-alive 使用持久的HTTP(S)连接
  41. –null-connection 从没有实际的HTTP响应体中检索页面长度
  42. –threads=THREADS 最大的HTTP(S)请求并发量(默认为1)
  43. Injection(注入):
  44. 这些选项可以用来指定测试哪些参数, 提供自定义的注入payloads和可选篡改脚本。
  45. -p TESTPARAMETER 可测试的参数(S)
  46. –dbms=DBMS 强制后端的DBMS为此值
  47. –os=OS 强制后端的DBMS操作系统为这个值
  48. –prefix=PREFIX 注入payload字符串前缀
  49. –suffix=SUFFIX 注入payload字符串后缀
  50. –tamper=TAMPER 使用给定的脚本(S)篡改注入数据
  51. Detection(检测):
  52. 这些选项可以用来指定在SQL盲注时如何解析和比较HTTP响应页面的内容。
  53. –level=LEVEL 执行测试的等级(1-5,默认为1)
  54. –risk=RISK 执行测试的风险(0-3,默认为1)
  55. –string=STRING 查询时有效时在页面匹配字符串
  56. –regexp=REGEXP 查询时有效时在页面匹配正则表达式
  57. –text-only 仅基于在文本内容比较网页
  58. Techniques(技巧):
  59. 这些选项可用于调整具体的SQL注入测试。
  60. –technique=TECH SQL注入技术测试(默认BEUST)
  61. –time-sec=TIMESEC DBMS响应的延迟时间(默认为5秒)
  62. –union-cols=UCOLS 定列范围用于测试UNION查询注入
  63. –union-char=UCHAR 用于暴力猜解列数的字符
  64. Fingerprint(指纹):
  65. -f, –fingerprint 执行检查广泛的DBMS版本指纹
  66. Enumeration(枚举):
  67. 这些选项可以用来列举后端数据库管理系统的信息、表中的结构和数据。此外,您还可以运行您自己
  68. 的SQL语句。
  69. -b, –banner 检索数据库管理系统的标识
  70. –current-user 检索数据库管理系统当前用户
  71. –current-db 检索数据库管理系统当前数据库
  72. –is-dba 检测DBMS当前用户是否DBA
  73. –users 枚举数据库管理系统用户
  74. –passwords 枚举数据库管理系统用户密码哈希
  75. –privileges 枚举数据库管理系统用户的权限
  76. –roles 枚举数据库管理系统用户的角色
  77. –dbs 枚举数据库管理系统数据库
  78. –tables 枚举的DBMS数据库中的表
  79. –columns 枚举DBMS数据库表列
  80. –dump 转储数据库管理系统的数据库中的表项
  81. –dump-all 转储所有的DBMS数据库表中的条目
  82. –search 搜索列(S),表(S)和/或数据库名称(S)
  83. -D DB 要进行枚举的数据库名
  84. -T TBL 要进行枚举的数据库表
  85. -C COL 要进行枚举的数据库列
  86. -U USER 用来进行枚举的数据库用户
  87. –exclude-sysdbs 枚举表时排除系统数据库
  88. –start=LIMITSTART 第一个查询输出进入检索
  89. –stop=LIMITSTOP 最后查询的输出进入检索
  90. –first=FIRSTCHAR 第一个查询输出字的字符检索
  91. –last=LASTCHAR 最后查询的输出字字符检索
  92. –sql-query=QUERY 要执行的SQL语句
  93. –sql-shell 提示交互式SQL的shell
  94. Brute force(蛮力):
  95. 这些选项可以被用来运行蛮力检查。
  96. –common-tables 检查存在共同表
  97. –common-columns 检查存在共同列
  98. User-defined function injection(用户自定义函数注入):
  99. 这些选项可以用来创建用户自定义函数。
  100. –udf-inject 注入用户自定义函数
  101. –shared-lib=SHLIB 共享库的本地路径
  102. File system access(访问文件系统):
  103. 这些选项可以被用来访问后端数据库管理系统的底层文件系统。
  104. –file-read=RFILE 从后端的数据库管理系统文件系统读取文件
  105. –file-write=WFILE 编辑后端的数据库管理系统文件系统上的本地文件
  106. –file-dest=DFILE 后端的数据库管理系统写入文件的绝对路径
  107. Operating system access(操作系统访问):
  108. 这些选项可以用于访问后端数据库管理系统的底层操作系统。
  109. –os-cmd=OSCMD 执行操作系统命令
  110. –os-shell 交互式的操作系统的shell
  111. –os-pwn 获取一个OOB shell,meterpreter或VNC
  112. –os-smbrelay 一键获取一个OOB shell,meterpreter或VNC
  113. –os-bof 存储过程缓冲区溢出利用
  114. –priv-esc 数据库进程用户权限提升
  115. –msf-path=MSFPATH Metasploit Framework本地的安装路径
  116. –tmp-path=TMPPATH 远程临时文件目录的绝对路径
  117. Windows注册表访问:
  118. 这些选项可以被用来访问后端数据库管理系统Windows注册表。
  119. –reg-read 读一个Windows注册表项值
  120. –reg-add 写一个Windows注册表项值数据
  121. –reg-del 删除Windows注册表键值
  122. –reg-key=REGKEY Windows注册表键
  123. –reg-value=REGVAL Windows注册表项值
  124. –reg-data=REGDATA Windows注册表键值数据
  125. –reg-type=REGTYPE Windows注册表项值类型
  126. General(一般):
  127. 这些选项可以用来设置一些一般的工作参数。
  128. -t TRAFFICFILE 记录所有HTTP流量到一个文本文件中
  129. -s SESSIONFILE 保存和恢复检索会话文件的所有数据
  130. –flush-session 刷新当前目标的会话文件
  131. –fresh-queries 忽略在会话文件中存储的查询结果
  132. –eta 显示每个输出的预计到达时间
  133. –update 更新SqlMap
  134. –save file保存选项到INI配置文件
  135. –batch 从不询问用户输入,使用所有默认配置。
  136. Miscellaneous(杂项):
  137. –beep 发现SQL注入时提醒
  138. –check-payload IDS对注入payloads的检测测试
  139. –cleanup SqlMap具体的UDF和表清理DBMS
  140. –forms 对目标URL的解析和测试形式
  141. –gpage=GOOGLEPAGE 从指定的页码使用谷歌dork结果
  142. –page-rank Google dork结果显示网页排名(PR)
  143. –parse-errors 从响应页面解析数据库管理系统的错误消息
  144. –replicate 复制转储的数据到一个sqlite3数据库
  145. –tor 使用默认的Tor(Vidalia/ Privoxy/ Polipo)代理地址
  146. –wizard 给初级用户的简单向导界面
  147. //–http://blog.csdn.net/ghosttzs–//

举例

python sqlmap.py -u “http://www.xxx.com?id=1” –level=5 –dbs

会使用最高优获取数据库表

 

sqlmap的下载文件:https://pan.baidu.com/s/1dFmhV2L