quarantin / ModGuardian

A set of tools to implement some form of copy protection for Project Zomboid mods.
3 stars 1 forks source link

Is there a way to do it in detail? #1

Open Work991 opened 1 year ago

Work991 commented 1 year ago

Is there a way to do it in detail? i want to study.

quarantin commented 1 year ago

Hi, thank you for your interest in ModGuardian. However I don't understand what you mean. To do what in details?

Work991 commented 1 year ago

Example of adding Blacklist players ,Blacklist servers and Make your mod exclusive or explain how to install more

quarantin commented 1 year ago

Oh, my bad. Well it's currently not in a working state but I'm getting really close to it, maybe I'll push an update later today. My goal is to be able to use it like this:

require("ModGuardian/ModGuardian")({
        modID = "YourModID",
        workshopID = "YourWorkshopID",
        playerBlacklist = {
            "750043204923432" -- Steam ID
        },
        serverBlacklist = {
            "1.2.3.4" -- Server IP
        },
        exclusiveServers = {
            "2.3.4.5" -- Server IP
        }
})

Basically just add this code anywhere in your mod, ideally at top level / global scope and like in the middle of the code, not at the beginning nor at the end, to make it harder to spot it. Also please note it makes no sense to use serverBlacklist and exclusiveServers together, because if you're using exclusiveServers, only servers in that list will be able to run the mod.

Then to obfuscate your mod, you need to run ModGuardian.py. The install steps are as follow (this is assuming you already cloned the repository and you have a valid python3 installation):

python3 -m venv env
. env/bin/activate
pip install -r requirements.txt

Then to run ModGuardian.py:

python3 ModGuardian.py /path/to/your/mod

(the path has to be the path to the folder containing the mod.info of your mod.) Then your obfuscated mod will be available at: /path/to/your/mod.obfuscated

Work991 commented 1 year ago

Server IP Can it be used as ddns?
ex Server1.ddns.net

quarantin commented 1 year ago

That's a good question.

I use getServerIP() to get the server address. From what I can decompile, the code for this function looks like this:

                @LuaMethod(name = "getServerIP", global = true)
                public static String getServerIP() {
                        if (GameServer.bServer) {
                                return GameServer.IPCommandline == null ? GameServer.ip : GameServer.IPCommandline;
                        } else {
                                return GameClient.bClient ? GameClient.ip : "";
                        }
                }

So according to the variables names, it looks like it's really the IP address, however some testing would be required in order to be sure. Maybe you can try to start your server with the following flag: -ip Server1.ddns.net and see if the server is starting/working properly.

That said I'm not sure it would be a good idea to use the domain name because it's really easy for end users / server owners to fake response to DNS queries, which could be used to bypass this protection.

Alternatively, if you know how to uniquely identify a server from Lua, in a way that is not easily changed by the server operator, I'd definitely use it. I checked a bit (not thoroughly though) but couldn't find anything useful except the IP.

Work991 commented 1 year ago

image

image Will the example look like this?

quarantin commented 1 year ago

Yes.

But you have to replace YourModID with your actual modID, and YourWorkshopID (or VanillaVehicles in your case) with your actual workshop ID. Also you might want to empty the playerBlacklist and serverBlacklist tables to avoid blacklisting random people/servers :sweat_smile:

quarantin commented 1 year ago

FYI, I just pushed an update, it should be working for the most part. There still might be some cases where the code transformation is breaking the mod though. You can also try to obfuscate ModGuardian itself if you're feeling adventurous :joy: Simply do:

python3 ModGuardian.py ModGuardian

and you'll get the obfuscated copy in ModGuardian.obfuscated

Don't hesitate to share code if you encounter problems, so that I can help you with the troubleshooting part.

Work991 commented 1 year ago

FYI, I just pushed an update, it should be working for the most part. There still might be some cases where the code transformation is breaking the mod though. You can also try to obfuscate ModGuardian itself if you're feeling adventurous :joy: Simply do:

python3 ModGuardian.py ModGuardian

and you'll get the obfuscated copy in ModGuardian.obfuscated

Don't hesitate to share code if you encounter problems, so that I can help you with the troubleshooting part.

I will try it soon

Work991 commented 1 year ago

image It can work fine but for VanillaVehicles.lua up to warn that ("ModGuardian/loader") failed.

quarantin commented 1 year ago

I'll try to check it out tomorrow

quarantin commented 1 year ago

Could you share the link to the corresponding mod on the workshop? I can see many different mods with vanilla vehicles in the name, so I'm not sure which one you're talking about.

Work991 commented 1 year ago

Could you share the link to the corresponding mod on the workshop? I can see many different mods with vanilla vehicles in the name, so I'm not sure which one you're talking about.

https://steamcommunity.com/sharedfiles/filedetails/?id=2984923559

https://steamcommunity.com/sharedfiles/filedetails/?id=2982271070 Original

quarantin commented 1 year ago

OK I think I understand the problem. 1) You have to add require=ModGuardian to your mod.info. (My bad, I forgot to add it to the documentation) 2) Your code is in shared, ModGuardian is in client, so your code can't call into ModGuardian (the require() will not work). I will try to find a way to address this. (just so you know I have a few ideas about how to work around this restriction)

Work991 commented 1 year ago

OK I think I understand the problem.

  1. You have to add require=ModGuardian to your mod.info. (My bad, I forgot to add it to the documentation)
  2. Your code is in shared, ModGuardian is in client, so your code can't call into ModGuardian (the require() will not work). I will try to find a way to address this. (just so you know I have a few ideas about how to work around this restriction)

Do I need to copy the ModGuardian folder to work with it? loader.lua ModGuardian.lua ModGuardianPopup.lua

quarantin commented 1 year ago

No. I have to find a way to make it work for code in server/shared. For now it can only work for code in client. Modguardian should be added as a mod though, for example in Zomboid/mods

Work991 commented 1 year ago

No. I have to find a way to make it work for code in server/shared. For now it can only work for code in client. Modguardian should be added as a mod though, for example in Zomboid/mods

Solve the problem by uploading the ModGuardian mod to the server so that the VanillaVehicles TT mod can be run?

quarantin commented 1 year ago

I'm not sure but I kind of remember it was not possible to add mods to a server unless it's available on the workshop. For now you'll have to try it locally. But it won't work until I find a way to make it work for code in media/lua/server or in media/lua/shared.

quarantin commented 1 year ago

It's not production ready to be pushed to the workshop, I'm still in very early development phase. But you can upload it privately to the workshop if you want. Make it unlisted so it won't be visible publicly, but you're server will still be able to download it.

Work991 commented 1 year ago

It's not production ready to be pushed to the workshop, I'm still in very early development phase. But you can upload it privately to the workshop if you want. Make it unlisted so it won't be visible publicly, but you're server will still be able to download it.

Thanks, I'll wait for the perfect one.

Work991 commented 1 year ago

image

    exclusiveServers = {
        "58.136.80.xx"                  -- Server IP. Clear this list if you don't need your mod to be exclusive to your server
    }

    There seems to be a malfunction.
quarantin commented 1 year ago

Can you describe your test? I understand that you made the mod exclusive, but the IP is not valid so it can't match your server. You should get an error about the server not being in the exclusive list. Yet the error message is about modpacks, eventhough your mod is not in a modpack. Is that correct?

quarantin commented 1 year ago

hum, the error message suggest you put wrong value in modID/workshopID. Can you show me your ModGuardian config?

Work991 commented 1 year ago
require("ModGuardian/ModGuardian")({
    modID = "2985969071",
    workshopID = "license",
    playerBlacklist = {
        "76561198351852922" -- Steam ID
    },
    exclusiveServers = {
        "58.136.80.21" -- Server IP
    }
})
name=license
id=license
require=ModGuardian
description=
poster=poster.png

ro```

require("ModGuardian/ModGuardian")({
    modID = "2985969071",
    workshopID = "license",
    playerBlacklist = {
        "76561198351852922" -- Steam ID
    },
    exclusiveServers = {
        "xxxxx.ddns.net" -- Server IP
    }
})
Work991 commented 1 year ago

mod is not in a modpack

quarantin commented 1 year ago

Yeah basically workshop ID is numeric while mod ID is alphanumeric

Work991 commented 1 year ago

Yeah basically workshop ID is numeric while mod ID is alphanumeric

Yeah basically workshop ID is numeric while mod ID is alphanumeric

Sorry, I forgot to notice.

Work991 commented 1 year ago

image

require("ModGuardian/ModGuardian")({
    modID = "license",
    workshopID = "2985969071",
    playerBlacklist = {"76561198351852922", "76561198030887119", "76561199013088252", "76561199013088252",
                       "76561198967687349"
    },
    exclusiveServers = {"58.136.80.21" -- Server IP
    }
})
quarantin commented 1 year ago

OK now that seems to be a bug indeed. Will try to fix it today

quarantin commented 1 year ago

I know it's probably not your case, but I'm very happy you were able to trigger the popup at least :joy:

quarantin commented 1 year ago

OK, I just pushed an update that should fix the modpack detection. I force pushed the branch, so you'll have to do this to update your local repository:

git fetch
git reset --hard origin/main

If you made any edit in ModGuardian, save those edits before, otherwise they'll be lost.

Work991 commented 1 year ago

OK, I just pushed an update that should fix the modpack detection. I force pushed the branch, so you'll have to do this to update your local repository:

git fetch
git reset --hard origin/main

If you made any edit in ModGuardian, save those edits before, otherwise they'll be lost.

    exclusiveServers = {"1dxxxxxx1.ddns.net" -- Server IP
    }

ip can bypass defenses but can prevent stream blacklist

quarantin commented 1 year ago

yeah not sure you can use DNS. Have you done some testing to see if you could configure pz so that getServerIP() would return a domain name and not an IP address?

Work991 commented 1 year ago

Owner

getServerIP() in -debug ? or serverIP = getServerIP() in server.ini

quarantin commented 1 year ago

Try to start the pzserver with this option on the command line:

-ip yourdomain.ddns.net

Then in debug mode you can type this in Lua console:

print(getServerIP())
Work991 commented 1 year ago
    serverBlacklist = {
            "58.136.xx.xx"                  -- Server IP. Clear this list if you don't have any server you want blacklisted
    },  
    exclusiveServers = {
        "2xxxxx2.ddns.net" -- Server IP
    }

})

can't block ip server 58.136.80.21

image

It seems that the file is missing the previous, version there are 3 files?

quarantin commented 1 year ago

My bad, not sure what happened but one of the file got deleted when I updated the code on github. The missing file should be available now. When you say it can't block IP, I suppose you had an error number within a red square visible in game (bottom-right corner of the screen)? If yes, please try again with the missing file.

Work991 commented 1 year ago

My bad, not sure what happened but one of the file got deleted when I updated the code on github. The missing file should be available now. When you say it can't block IP, I suppose you had an error number within a red square visible in game (bottom-right corner of the screen)? If yes, please try again with the missing file.

Does it work for code in media/lua/server or in media/lua/shared?

quarantin commented 1 year ago

I managed to move most of ModGuardian code to shared, and I know it's working for a mod with code in client, but haven't tested yet if it really work when the mod has code in shared and server. So I don't know to be honest :sweat_smile:

quarantin commented 1 year ago

Also it's probably not working in MP yet. I have a few things to figure out first

Work991 commented 1 year ago

I managed to move most of ModGuardian code to shared, and I know it's working for a mod with code in client, but haven't tested yet if it really work when the mod has code in shared and server. So I don't know to be honest ๐Ÿ˜…

I tested in MP only.

Work991 commented 1 year ago

There's already a jumping zombies. I want a ghost jumping over the compost bin . Players like to think it's very easy to defend against zombies. I don't have an aptitude for animation zombies.

quarantin commented 1 year ago

Are you sure you posted your last message to the right place? It feels like you're talking about something completely different :sweat_smile:

Work991 commented 1 year ago

๐Ÿ˜… i'm test serverBlacklist,playerBlacklist it can be used

Work991 commented 1 year ago

image but there is a problem


   exclusiveServers = {
        "58.136.xx.xx" -- Server IP
    }
```เน‰
have run  `UI_ModGuardian_Text_Modpack  `
quarantin commented 1 year ago

Can you share full config? Also you're testing this on a pz server right?

Work991 commented 1 year ago

yes


Zomboid\mods\ModGuardian in pc 
and
/home/pzserver10/Zomboid/mods/ModGuardian pzserver

Mods=ModGuardian;license WorkshopItems=2985969071

require("ModGuardian/ModGuardian")({ modID = "license", workshopID = "2985969071", playerBlacklist = {"76561198351852922", "76561198030887119", "76561199013088252", "76561199013088252" }, exclusiveServers = { "58.136.8x.xx" -- Server IP } })

quarantin commented 1 year ago

Can you go to ModGuardian git repo and show me the result of this command please?

git rev-parse HEAD

Also you're using the main branch right?

Work991 commented 1 year ago

Can you go to ModGuardian git repo and show me the result of this command please?

git rev-parse HEAD

Also you're using the main branch right?

image

quarantin commented 1 year ago

Ok it's the correct commit. Sorry but I don't know what's the problem yet. I'll have to investigate, but I'm running short of time for today. I will check this tomorrow. And thanks for your motivation and contribution, please know that it's really appreciated :)