用于在多台服务器上单点登录SSO、无SESSION,用户身份的 验证 。 1、安装lua yum install readline.x86_64 readline-devel.x86_64 wget http://www.lua.org/ftp/lua-5.1.5.tar.gz make linux make install 注意:不要使用5.2版本,5.2版本的lua和nginx的整合
用于在多台服务器上单点登录SSO、无SESSION,用户身份的验证。
1、安装lua
yum install readline.x86_64 readline-devel.x86_64
- wget http://www.lua.org/ftp/lua-5.1.5.tar.gz
- make linux
- make install
- LUA_GLOBALSINDEX' undeclared (first use in this function)
参考:https://github.com/LuaLanes/lanes/issues/18
2、编译nginx
下载lua-nginx-module
- wget https://github.com/chaoslawful/lua-nginx-module/zipball/master
- file master
- unzip master
- mv chaoslawful-lua-nginx-module-06d654b/ lua-nginx-module
下载ngx_devel_kit
- https://github.com/simpl/ngx_devel_kit/zipball/master
- file master
- unzip master
- mv simpl-ngx_devel_kit-4192ba6/ simpl-ngx_devel_kit
- tar -xvzf nginx-1.2.1.tar.gz
- ./configure \
- --prefix=/usr/local/nginx \
- --with-http_stub_status_module \
- --without-poll_module \
- --without-select_module \
- --with-http_ssl_module \
- --with-http_realip_module \
- --with-http_perl_module \
- --add-module=../simpl-ngx_devel_kit \
- --add-module=../lua-nginx-module
make install
2、测试lua
测试
- location = /lua {
- content_by_lua '
- ngx.say("Hello, Lua!")
- ';
- }
3、登录验证
nginx添加配置
- access_by_lua_file 'conf/access.lua';
可以根据需要添加更多的验证域
- local secretkey='1234567890abcdefghi'
- if ngx.var.cookie_uid == nil or ngx.var.cookie_token == nil then
- ngx.req.set_header("Check-Login", "NULL")
- return
- end
-
- --local ctoken = ngx.md5('uid:' .. ngx.var.cookie_uid .. '&secretkey:' .. secretkey)
- local ctoken = ngx.md5(ngx.var.cookie_uid .. secretkey)
- if ctoken == ngx.var.cookie_token then
- ngx.req.set_header("Check-Login", "YES")
- else
- ngx.req.set_header("Check-Login", "NO")
- end
- return
如果uid+lua中的securekey的md5值和请求中的cookie的值一致,则设置request header中的HTTP_CHECK_LOGIN为YES,否则为No,如果不存在uid或token这两个cookie中的一个,则HTTP_CHECK_LOGIN设置为NULL。
关于Check-Login,HTTP_CHECK_LOGIN:
lua中设置的heaer为Check-Login,输出后就变成了HTTP_CHECK_LOGIN,即前面加了HTTP_,经过测试,有些会添加HTTP_,而有些则不会添加,如Content-Type。
详细信息查看:http://wiki.nginx.org/HttpLuaModule#ngx.req.set_header
4、测试
使用perl cgi
perl打印ENV
-
#!/usr/bin/perl -w
-
use strict;
-
use CGI;
- use Data::Dumper;
-
-
my $query = new CGI;
-
print $query->header('text/html');
-
-
print Dumper \%ENV;
-
-
#if ($ENV{HTTP_CHECK_LOGIN} ne "YES"){
-
# print "not auth";
-
# exit;
- #}
注释部分是一个例子,针对认证的结果做更多的操作。
可以使用curl来带着cookie进行测试:
curl -b "uid=1234;token=8323d8c4a0533dc78c7051a074cdb286" http://127.0.0.1/7.cgi
如果使用echo 打印md5值,需要使用-n参数去掉回车
echo -n 123456789|md5sum
如何查看lua生成的md5?
location = /lua {
content_by_lua '
local ctoken = ngx.md5("12345" .. "6789")
ngx.say(ctoken)
';
}
关于查看access.lua生成的cookie
- local secretkey='cookiesecretKey'
- if ngx.var.cookie_uid == nil or ngx.var.cookie_token == nil then
- ngx.req.set_header("Check-Login", "NULL")
- return
- end
- --local ctoken = ngx.md5('uid:' .. ngx.var.cookie_uid .. '&secretkey:' .. secretkey)
- local ctoken = ngx.md5(ngx.var.cookie_uid .. secretkey)
- if ctoken == ngx.var.cookie_token then
- ngx.req.set_header("Check-Login", "YES")
- print (ctoken)
- print (ngx.var.cookie_token)
- else
- ngx.req.set_header("Check-Login", "NO")
- print (ctoken)
- print (ngx.var.cookie_token)
- end
- return
打开nginx的log到debug,从error里可以看到access.lua的输出
通过html种植cookie
-
html xmlns="http://www.w3.org/1999/xhtml">
-
head>
-
meta http-equiv="Content-Type" content="text/html; charset=gbk">
-
/head>
-
-
body>
-
p>
-
script>
-
document.cookie="domain=intercom.com.cn";
-
document.cookie="uid=1234";
-
document.cookie="token=dbd19902c04fdc68ee8b97510f454614";
-
//document.cookie="expires=Sat, 31-Dec-39 23:59:59 GMT";
-
document.write(document.cookie);
-
/script>
-
/p>
-
/body>
- /html>

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor
