Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error when IPv6 log client #7

Closed
thelittlefireman opened this issue Dec 28, 2020 · 2 comments
Closed

Runtime error when IPv6 log client #7

thelittlefireman opened this issue Dec 28, 2020 · 2 comments

Comments

@thelittlefireman
Copy link

thelittlefireman commented Dec 28, 2020

hi,

I've got a nil issue when bouncer is using a nginx log which contains an ipv6.

2020/12/28 21:59:25 [error] 9518#9518: *80 lua entry thread aborted: runtime error: /usr/local/lib/lua/crowdsec/CrowdSec.lua:18: attempt to perform arithmetic on local 'o1' (a nil value)#012stack traceback:#012coroutine 0:#012#011/usr/local/lib/lua/crowdsec/CrowdSec.lua: in function 'ipToInt'#012#011/usr/local/lib/lua/crowdsec/CrowdSec.lua:70: in function 'allowIp'#012#011access_by_lua(main-lua.conf:166):105: in main chunk, client: 2a01:e0a:169:7f90::d73a:9b9d, server: nextcloud.mydomain, request: "PROPFIND /remote.php/dav/files/user/ HTTP/1.1", host: "nextcloud.mydomain"

original nginx log :

==> /var/log/access.log <==
2a01:e0a:169:7f90::d73a:9b9d - user nextcloud.mydomain [28/Dec/2020:21:59:25 +0100] "PROPFIND /remote.php/dav/files/user/ HTTP/1.1" 500 170 "-" "Mozilla/5.0 (Linux) mirall/3.1.1-20201225.075704.75c329f4f-1.0~groovy1 (Nextcloud)"
@thelittlefireman
Copy link
Author

thelittlefireman commented Dec 28, 2020

solution

function ipv6toInt ( str )
    local o1,o2,o3,o4,o5,o5,o6,o7,o8 = str:match("(%w+):(%w+):(%w+):(%w+):(%w+):(%w+):(%w+):(%w+)" )
    print (o1)
    local num = 0
    if o1 ~= nil then
        num=num+2^56*tonumber(o1,16)
    end
    if o2 ~= nil then
        num=num+2^48*tonumber(o2,16)
    end
    if o3 ~= nil then
        num=num+2^40*tonumber(o3,16)
    end
    if o4 ~= nil then
        num=num+2^32*tonumber(o4,16)
    end
    if o5 ~= nil then
        num=num+2^24*tonumber(o5,16)
    end
    if o6 ~= nil then
        num=num+2^16*tonumber(o6,16)
    end
    if o7 ~= nil then
        num=num+2^8*tonumber(o7,16)
    end
    if o8 ~= nil then
        num=num+tonumber(o8,16)
    end
    return num
end

function ipToInt( str )
	local num = 0
	if str and type(str)=="string" then
                if str:find(".", 4,true) then
		            local o1,o2,o3,o4 = str:match("(%d+)%.(%d+)%.(%d+)%.(%d+)" )
		            num = 2^24*o1 + 2^16*o2 + 2^8*o3 + o4
                else
                    num = ipv6toInt (str)
                end
	end
    return num
end


print(ipToInt("2a01:e0a:169:7f90::d73a:9b9d"))
print(ipToInt("0000:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"))
print(ipToInt("0.0.3.0"))


thelittlefireman added a commit to thelittlefireman/lua-cs-bouncer that referenced this issue Dec 28, 2020
@thelittlefireman
Copy link
Author

wrong test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant