Lua-FiveM-Malware-Guard
Lua FiveM Malware Guard: A powerful resources extension for FiveM servers owners to enhance server security by preventing unauthorized Lua functions, managing resource permissions, and receiving real-time alerts via Discord webhooks.
Lua FiveM Malware Guard is a security-focused resources extension for FiveM servers owners. It is designed to prevent the usage of Lua functions such as os.execute, os.getenv, io.popen etc., and sensitive FiveM native functions in resources, and it allows the server owner to assign permissions to each resource to specify which functions are allowed. The resource also includes a Discord webhook system for alerting administrators of trigger attempts, with three levels of alerts: normal, high, and very high.
- Demo
- Features
- File Structure
- Usage Steps
- Configuration
- Testing
- ToDo List
- Functions Covered
- How to Contribute
- Contact
- License
- Disclaimer and Limitations
- Prevent the usage of sensitive Lua functions and sensitive FiveM native functions.
- Control resource-level permissions for specific functions.
- Discord webhook integration for real-time alerts.
- Three levels of alerts (normal, high, very high).
- Zero Dependencies.
- Compatibility with All Frameworks, Whether you're using ESX, QBCore, vRP, or any other framework.
- Cross-Platform Compatibility with both Windows and Linux.
- Anti-Debugging and Override System.
- Centralized config via convars — one
config.luacontrols webhooks, verbosity, function defaults, overrides, and whitelist for all resources. - Folder-based whitelisting with nested folder support (e.g.
[DRM]/[PAIDSCRIPTS]/resource). - Per-resource and per-folder function control overrides — customize which functions are monitored or blocked for any resource or folder.
- Whitelisted resources with overrides — whitelist a resource but still monitor specific functions, with
m3lm_listshowing[WHITELISTED(-n)]markers. - Windows PowerShell deployer script that automatically distributes
m3lm_protection.luato all applicable resources, including network drive support.
m3lm_guard/
├── config.lua ← webhooks, verbosity level, whitelist
├── fxmanifest.lua
├── server/
│ └── main.lua ← pushes config convars at startup
├── citizen_scripts/
│ ├── m3lm_protection.lua ← distributed to each resource by the deployer
│ └── resource_init.lua ← copy this to citizen/scripting/ on your server
├── Deploy-Protection.ps1 ← auto-deploys m3lm_protection.lua to all resources
└── Deploy-Protection.bat ← double-click launcher for the deployer on Windows
m3lm_test/ ← optional test resource (harmless)
├── fxmanifest.lua
└── server/
└── test.lua ← run m3lm_runtest in console to verify guard
Note:
protection.luahas been renamed tom3lm_protection.luato avoid conflicts with other resources that ship their ownprotection.luafile.
-
Locate
citizen/scripting/resource_init.luawithin your FiveM server build files and replace it withcitizen_scripts/resource_init.luafrom this project. This ensuresm3lm_protection.luais injected into every resource's manifest automatically. -
Place the
m3lm_guardresource folder into your server'sresources/directory. -
Add
ensure m3lm_guardto yourserver.cfgbefore all other resources so convars are set before anything else loads. -
Open
m3lm_guard/config.luaand configure your Discord webhook URLs, verbose level, and whitelist. -
Run
Deploy-Protection.bat(Windows) to automatically copym3lm_protection.luainto every unwhitelisted resource folder. Re-run this whenever you add new resources or change the whitelist. -
Reboot your server twice:
- First boot:
m3lm_guardstarts and pushes config convars. - Second boot: all resources load with
m3lm_protection.luaactive and reading the correct config.
- First boot:
All configuration lives in config.lua:
Config.Webhooks = {
Normal = 'YOUR_WEBHOOK_URL', -- level 1 alerts
High = 'YOUR_WEBHOOK_URL', -- level 2 alerts
VeryHigh = 'YOUR_WEBHOOK_URL', -- level 3 alerts
}
-- 0 = silent, 1 = blocks only (default), 2 = all calls
Config.VerboseLevel = 1
-- Global function defaults — true = allow, false = block
-- See config.lua for the full list and legend
Config.FunctionDefaults = {
PerformHttpRequest = true,
os_execute = true,
os_getenv = false, -- blocked by default
io_popen = true,
ExecuteCommand = true,
}
-- Per-resource or per-folder function overrides
-- Merged on top of FunctionDefaults for normal resources
-- Only list the functions you want to change from the defaults
Config.Overrides = {
['my_shop'] = { PerformHttpRequest = false }, -- block HTTP for this resource
['[my-folder]'] = { ExecuteCommand = false }, -- block for whole folder
}
-- Whitelist — skip protection entirely
-- Supports nested folders e.g. ['[DRM]'] matches [DRM]/[PAIDSCRIPTS]/resource
Config.Whitelist = {
['[DRM]'] = true, -- skip entire folder tree
['my_trusted_resource'] = true, -- skip a single resource
}A resource can be in both Whitelist and Overrides at the same time. It will be skipped for full protection but will still monitor only the explicitly listed functions — everything else is untouched:
Config.Whitelist = { ['[DRM]'] = true }
Config.Overrides = {
['[DRM]'] = {
PerformHttpRequest = true, -- monitor license checks
os_execute = false, -- block — DRM should never need this
},
}These show as [WHITELISTED(-n)] in m3lm_list where n is the number of override functions.
Deploy-Protection.bat reads the whitelist and overrides directly from config.lua. Run it whenever you:
- Add new resources
- Change config
- Update
m3lm_protection.lua
The deployer runs in two passes:
- Clean — removes all existing
m3lm_protection.luafiles - Deploy — copies
m3lm_protection.luainto every applicable resource, including whitelisted resources that have overrides
A harmless test resource m3lm_test is included to verify that m3lm_protection.lua is working correctly in your server environment.
- Place
m3lm_testin yourresources/folder - Add
ensure m3lm_testtoserver.cfg - Run
Deploy-Protection.batsom3lm_protection.luagets copied intom3lm_test - Reboot your server
Type the following in your server console:
m3lm_runtest
| Test | Expected Result |
|---|---|
os.getenv |
Blocked by guard |
os.execute with dangerous command (rm -rf) |
Blocked by guard |
os.execute with bypass attempt (resource_init) |
Blocked by guard |
os.execute with safe command |
Nil (FiveM engine sandbox) |
io.popen with dangerous command (curl) |
Blocked by guard |
io.popen with safe command |
Nil (FiveM engine sandbox) |
SaveResourceFile |
Allowed and logged |
PerformHttpRequest |
Allowed and logged (async) |
ExecuteCommand |
Allowed and logged |
Guard alerts from m3lm_protection.lua should appear interleaved with the test results:
[script:m3lm_test] [m3lm_guard:m3lm_test] os.getenv: BLOCKED: PATH
[script:m3lm_test] [m3lm_guard:m3lm_test] os.execute: BLOCKED: rm | rm -rf ...
[script:m3lm_test] [m3lm_guard:m3lm_test] io.popen: BLOCKED: curl | curl http://example.com
Note:
m3lm_testis purely a diagnostic tool. It never executes any dangerous commands — dangerous strings are passed as arguments but the guard blocks them before any real execution occurs. Safe to run on a live server.
If you're interested in contributing to FiveM SecurityGuard, here are some tasks that need attention. Feel free to pick an item from the list, work on it, and submit a pull request. If you have new ideas or find issues not listed here, please open an issue to discuss them.
- Add more functions to enhance security coverage.
- Create Client Side functions security system, By using the TriggerServerEvent native to check.
- Explore the possibility of supporting other programming languages, such as JavaScript (JS) and C#.
- Implement additional security checks for the functions.
- Enhance the permission management system.
- Address any identified security vulnerabilities or bugs.
- Investigate and fix reported bugs or issues.
Here is a list of functions covered by Lua FiveM Malware Guard with descriptions and links to relevant documentation:
io.popen— Opens a pipe to execute a command and returns a file handle. Lua Documentationos.execute— Executes an operating system command. Lua Documentationos.clock— Returns an approximation of the amount in seconds of CPU time used by the program. Lua Documentationos.getenv— Retrieves the value of an environment variable. Lua Documentationos.remove— Removes a file or directory. Lua Documentationos.rename— Renames a file or directory. Lua Documentationio.read— Reads from a file. Lua Documentationio.open— Opens a file or returns a new file handle. Lua Documentationio.close— Closes the given file. Lua Documentationio.input— Sets the default input file. Lua Documentationio.write— Writes to the default output file. Lua Documentationio.stdin— The standard input file. Lua Documentationio.stdout— The standard output file. Lua Documentationio.stderr— The standard error file. Lua Documentationdebug.getinfo— Retrieves information about a function. Lua Documentationdebug.getlocal— Gets information about a local variable. Lua Documentationdebug.getupvalue— Gets the value of an upvalue from a function. Lua Documentationdebug.sethook— Sets a new hook function for debugging. Lua Documentation
GetCurrentServerEndpoint— Returns the endpoint URL of the current server. FiveM DocumentationStartResource— Starts a specified resource. FiveM DocumentationStopResource— Stops a specified resource. FiveM DocumentationSetResourceKvpFloat— Sets a floating-point key-value pair for a resource. FiveM DocumentationSetResourceKvpFloatNoSync— Sets a floating-point KVP without synchronizing. FiveM DocumentationSetResourceKvpInt— Sets an integer key-value pair for a resource. FiveM DocumentationSetResourceKvpIntNoSync— Sets an integer KVP without synchronizing. FiveM DocumentationSetResourceKvpNoSync— Sets a KVP without synchronizing. FiveM DocumentationSetResourceKvp— Sets a key-value pair for a resource. FiveM DocumentationSetHttpHandler— Sets a custom HTTP handler for resource-specific HTTP requests. FiveM DocumentationSetMapName— Sets the map name for the server. FiveM DocumentationSetGameType— Sets the game type for the server. FiveM DocumentationSetConvar— Sets the value of a convar for the server. FiveM DocumentationGetConvar— Retrieves the value of a convar for the server. FiveM DocumentationSetConvarReplicated— Sets a convar and replicates it to all clients. FiveM DocumentationSetConvarServerInfo— Sets a convar as a server info convar. FiveM DocumentationSaveResourceFile— Saves a file within a resource. FiveM DocumentationGetGameName— Retrieves the name of the game on the server. FiveM DocumentationGetGameBuildNumber— Retrieves the build number of the game. FiveM DocumentationGetCurrentResourceName— Retrieves the name of the currently executing resource. FiveM DocumentationPerformHttpRequest— Performs an HTTP request from the server. FiveM DocumentationDeleteFunctionReference— Deletes a reference to a specific function. FiveM DocumentationDeleteResourceKvp— Deletes a key-value pair associated with a resource. FiveM DocumentationDeleteResourceKvpNoSync— Deletes a KVP without synchronizing. FiveM DocumentationDuplicateFunctionReference— Creates a duplicate reference to a function. FiveM DocumentationEnableEnhancedHostSupport— Enables enhanced host support for the server. FiveM DocumentationExecuteCommand— Executes a console command on the server. FiveM DocumentationFlushResourceKvp— Flushes all key-value pairs for the current resource. FiveM DocumentationGetHashKey— Retrieves the hash value for a string. FiveM DocumentationGetHostId— Retrieves the host identifier of the server. FiveM DocumentationGetNumResources— Retrieves the number of loaded resources. FiveM DocumentationGetPasswordHash— Retrieves the hashed password of a player. FiveM DocumentationGetPlayerEndpoint— Retrieves the endpoint (IP and port) of a player. FiveM DocumentationGetPlayerIdentifier— Retrieves a player's identifier based on their server ID. FiveM DocumentationGetNumPlayerIdentifiers— Retrieves the number of identifiers for a player. FiveM DocumentationGetNumPlayerIndices— Retrieves the number of player indices on the server. FiveM DocumentationGetNumPlayerTokens— Retrieves the number of player tokens on the server. FiveM DocumentationGetNumResourceMetadata— Retrieves the number of metadata entries for a resource. FiveM DocumentationGetPlayerName— Retrieves the name of a player based on their server ID. FiveM DocumentationGetPlayerToken— Retrieves a player's token based on their server ID. FiveM DocumentationGetResourcePath— Retrieves the path of a resource on the server. FiveM DocumentationLoadPlayerCommerceData— Loads commerce data for a player. FiveM DocumentationLoadPlayerCommerceDataExt— Loads extended commerce data for a player. FiveM DocumentationLoadResourceFile— Loads a file from a resource and returns its contents as a string. FiveM DocumentationNetworkGetEntityFromNetworkId— Retrieves an entity based on its network ID. FiveM DocumentationNetworkGetEntityOwner— Retrieves the owner of a networked entity. FiveM DocumentationNetworkGetFirstEntityOwner— Retrieves the owner of the first networked entity found. FiveM DocumentationNetworkGetNetworkIdFromEntity— Retrieves the network ID of a networked entity. FiveM DocumentationNetworkGetVoiceProximityOverride— Retrieves the voice proximity override level for a player. FiveM DocumentationRegisterConsoleListener— Registers a console command listener callback function. FiveM DocumentationRegisterResourceAsset— Registers a file or directory as a resource asset. FiveM Documentation
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and test thoroughly.
- Create a pull request with a clear description of your changes.
- Open an Issue: If you encounter a technical issue or have a specific request related to the project.
- Compliance and Problem Reporting: For compliance-related matters or to report any problems contact via Email: info@m3lm.co.
- Discord Community: Join M3LM Games vibrant Discord community for chatting with fellow contributors, planning and showcasing your achievements, and inquiring.
- This project, Lua FiveM Malware Guard, is intended solely for educational and informational purposes. It is designed to provide a better understanding of potential security vulnerabilities within the FiveM platform and to help prevent the misuse of certain functions. The project's creators and contributors do not endorse or encourage any illegal or unethical activities, including but not limited to hacking, cheating, or any actions that violate the terms of service of the FiveM platform or the Laws.
- Users of this project are responsible for their own actions and are expected to adhere to all applicable laws and regulations. The project's creators and contributors are not responsible for any misuse, harm, or legal consequences resulting from the use of this project.
- It is essential to use this project responsibly and ethically, respecting the rules and policies of the FiveM platform and any relevant local, state, or federal laws. If you choose to use this project, you do so at your own risk, and the project's creators and contributors shall not be held liable for any actions or consequences arising from its use.
- By using this project, you acknowledge and agree to the terms of this disclaimer. If you do not agree with these terms, you should refrain from using or contributing to this project.



