Nginx + LuaJIT + Webhook

admin 2022年5月17日11:34:54安全博客评论8 views1892字阅读6分18秒阅读模式

Install

  • LuaJIT
  • ngx_devel_kit
  • lua-nginx-module
  • Nginx

Base

apt install make gcc git libpcre3 libpcre3-dev zlib1g-dev libssl-dev

Download and DeCompression

cd /usr/local/src

wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz
tar -zxvf LuaJIT-2.0.5.tar.gz
wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.1rc1.tar.gz
tar -zxvf v0.3.1rc1.tar.gz
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.12rc2.tar.gz
tar -zxvf v0.10.12rc2.tar.gz
wget http://nginx.org/download/nginx-1.13.12.tar.gz
tar -zxvf ~/nginx-1.13.12.tar.gz

Install LuaJIT

cd LuaJIT-2.0.5
make install PREFIX=/usr/local/luajit

echo "export LUAJIT_LIB=/usr/local/luajit/lib" > /etc/profile.d/luajit.sh
echo "export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0" >> /etc/profile.d/luajit.sh
source /etc/profile.d/luajit.sh

Install Nginx

cd ../nginx-1.13.12

./configure --add-module=/usr/local/src/ngx_devel_kit-0.3.1rc1 --add-module=/usr/local/src/lua-nginx-module-0.10.12rc2
make -j2 && make install

ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx

Configure

Server

mkdir -p /var/www/.ssh /var/www/html
chown -R www-data:www-data /var/www
sudo -Hu www-data ssh-keygen -t rsa
sudo -Hu www-data git clone [email protected]:yourname/yourrepo.git /var/www/html

add in nginx.conf

location /webhook {
    default_type 'text/plain';
    content_by_lua_file /var/www/webhook.lua;
}

/var/www/webhook.lua

local ffi = require("ffi")
local args = nil
local token = 'anything what your set for github secret'
local request_method = ngx.var.request_method
if "POST" == request_method then
    ngx.req.read_body()
    args = ngx.req.get_post_args()
    ffi.cdef[[int system(const char * string);]]
    if args['token'] == token and ffi.C.system("cd /var/www/html && git pull") then
        ngx.say("ok")
    else
        ngx.say("fuck")
    end
else
    ngx.say("fuck")
end

Github

Deploy keys

https://github.com/yourname/yourrepo/settings/keys

Add keys what you made just now

/var/www/.ssh/id_rsa.pub

WebHooks

https://github.com/yourname/yourrepo/settings/hooks

Secret is your token for /var/www/webhook.lua

Finish

Enjoy yourself!

FROM : virzz.com | Author:Virink

特别标注: 本站(CN-SEC.COM)所有文章仅供技术研究,若将其信息做其他用途,由用户承担全部法律及连带责任,本站不承担任何法律及连带责任,请遵守中华人民共和国安全法.
  • 我的微信
  • 微信扫一扫
  • weinxin
  • 我的微信公众号
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年5月17日11:34:54
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                  Nginx + LuaJIT + Webhook http://cn-sec.com/archives/1012950.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: