### Install and Start Service Source: https://documentation.greyscript.org/index Installs and starts a service. Returns 1 on success or a string with error details on failure. Causes a crash if the input is not a 'service' object. ```greyscript service = include_lib("/lib/libhttp.so") result = install_service(service) if result == 1 then print "Successfully installed service" else print "Service installation failed: " + result end if ``` -------------------------------- ### Install Service Source: https://documentation.greyscript.org/index Installs and starts a specified service using the provided library. It returns 1 on success or a string with error details on failure. Only root users can perform this action. ```greyscript service = include_lib("/lib/libhttp.so") result = service.install_service if result == 1 then print "Successfully installed service" else print "Service installation failed: " + result end if ``` -------------------------------- ### Install Program/Library using APT Client Source: https://documentation.greyscript.org/index Installs a program or library from a remote repository. It handles installing to '/lib' or '/bin' based on type if no path is specified. Returns 1 on success or an error message string on failure. Requires '/lib/aptclient.so'. ```greyscript aptClient = include_lib("/lib/aptclient.so") result = aptClient.install("rshell_interface") if result == 1 then print "Installed program successful!" else print "Error while installing: " + result end if ``` -------------------------------- ### Install Package with aptClient Source: https://documentation.greyscript.org/index Installs a program or library from a remote repository. Installs to '/lib' or '/bin' by default if no customPath is given. Returns a number (1 for success) or a string (error message). Returns null if parameters have incorrect types. ```greyscript aptClient = include_lib("/lib/aptclient.so") result = install(aptClient, "rshell_interface") if result == 1 then print "Installed program successful!" else print "Error while installing: " + result end if ``` -------------------------------- ### Start Reverse Shell Server in Greyscript Source: https://documentation.greyscript.org/index Initializes a reverse shell server to accept incoming connections. Requires the 'rshell' service to be installed. Returns a list of shell objects if connections are established, a string with error details on failure, or null if the input is not a 'metaxploit' object. ```greyscript metax = include_lib("/lib/metaxploit.so") shells = rshell_server(metax) firstShell = shells[0] chmod(File(host_computer(firstShell), "/"), "o-wrx", true) ``` -------------------------------- ### Start Reverse Shell Server Source: https://documentation.greyscript.org/index Initializes a reverse shell server to accept incoming shell connections. Requires the 'rshell' service to be installed on the receiving machine. Returns a list of shell objects on success or an error string on failure. ```greyscript metax = include_lib("/lib/metaxploit.so") shells = metax.rshell_server firstShell = shells[0] firstShell.host_computer.File("/").chmod("o-wrx", true) ``` -------------------------------- ### aptClient.install Source: https://documentation.greyscript.org/index Installs a program or library from a remote repository. It can install to '/lib' or '/bin' based on the type, or a specified path. Returns 1 on success, or an error message string on failure. ```APIDOC ## POST /apt/install ### Description Installs a program or library from a remote repository listed in `"/etc/apt/sources.txt"`. If no path is specified, the program installs in `"/lib"` if it is a library or in `"/bin"` otherwise. If any of the provided parameters have a type that deviates from the defined signature, the method will return `null`. On success, this method will return a `number` with the value one. In case of failure, it will return a `string` containing an error message. ### Method POST ### Endpoint /apt/install ### Parameters #### Query Parameters - **packageName** (string) - Required - The name of the package to install. - **path** (string) - Optional - The path where the package should be installed. Defaults to `/lib` or `/bin`. ### Request Example ```json { "packageName": "rshell_interface" } ``` ### Response #### Success Response (200) - **result** (number) - Returns 1 on successful installation. #### Error Response (400) - **error** (string) - Returns an error message if installation fails. #### Response Example ```json { "result": 1 } ``` ``` -------------------------------- ### Start Service with libhttp.so Source: https://documentation.greyscript.org/index Starts a service and opens its associated port. Requires port forwarding for external access. Returns 1 on success, or a string with error details on failure. Passing a non-service object will cause a crash. ```greyscript service = include_lib("/lib/libhttp.so") result = start_service(service) if result == 1 then print "Successfully started service" else print "Starting service failed: " + result end if ``` -------------------------------- ### Start Service Source: https://documentation.greyscript.org/index Starts a service and opens its associated port, making it accessible. Returns 1 on success or a string with error details on failure. Requires port forwarding for external access. Only root users can perform this action. ```greyscript service = include_lib("/lib/libhttp.so") result = service.start_service if result == 1 then print "Successfully started service" else print "Starting service failed: " + result end if ``` -------------------------------- ### mining Source: https://documentation.greyscript.org/index Starts the cryptocurrency mining process. Returns 1 on success or a string with error details on failure. ```APIDOC ## mining ### Description Starts the process of mining the cryptocurrency. The process keeps the terminal busy until a coin is mined. Returns `1` on success, a `string` with details on failure. Returns `null` if a non-`subWallet` object is passed. ### Method mining ### Parameters #### Arguments - **self** (subWallet) - The subWallet object to perform mining on. ### Request Example ```javascript blockchain = include_lib("/lib/blockchain.so") coin = get_coin(blockchain, "test", "test", "test") subWallet = get_subwallet(coin, "test") while subWallet.mining == 1 { print "Mining...", true print "Balance " + subWallet.get_balance } ``` ### Response - **number** or **string** or **null** - Returns `1` on success, a `string` with error details on failure, or `null` if the input is not a `subWallet`. ``` -------------------------------- ### String Manipulation Examples Source: https://documentation.greyscript.org/index Demonstrates basic string operations including concatenation, repetition, accessing characters by index, and slicing. ```Greyscript a = "hello" b = "world" print(a + b) // concatinate a and b print(a * 10) // repeat hello ten times print(a[0]) // prints h print(a[1:3]) // prints ell ``` -------------------------------- ### Mining API Source: https://documentation.greyscript.org/index Provides methods to start and manage the cryptocurrency mining process. This includes initiating mining, setting subwallet information, and retrieving wallet usernames. ```APIDOC ## POST /mine ### Description Starts the process of mining the cryptocurrency. The process leaves the terminal busy until a coin is mined. On success, this method will return a `number` with the value one. On failure, this method will return a `string` with details. ### Method POST ### Endpoint /mine ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **subWalletUser** (string) - Required - The identifier for the subwallet to be used for mining. - **coinName** (string) - Required - The name of the cryptocurrency to mine. ### Request Example ```json { "subWalletUser": "user123", "coinName": "BTC" } ``` ### Response #### Success Response (200) - **result** (number) - Returns 1 upon successful mining. #### Failure Response (Error String) - **error** (string) - Returns a string with details upon failure. #### Response Example (Success) ```json { "result": 1 } ``` #### Response Example (Failure) ```json { "error": "Error: GPU is damaged. Unable to start the mining process." } ``` ``` ```APIDOC ## PUT /subwallet/info ### Description Stores optional information in the Subwallet for any use. Upon success, a `number` with the value one will be returned. In case of failure, a `string` with details will be returned. ### Method PUT ### Endpoint /subwallet/info ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **subWalletUser** (string) - Required - The identifier for the subwallet. - **info** (string) - Required - The information to store in the subwallet. ### Request Example ```json { "subWalletUser": "user123", "info": "Additional notes for this subwallet." } ``` ### Response #### Success Response (200) - **result** (number) - Returns 1 upon successful storage of information. #### Failure Response (Error String) - **error** (string) - Returns a string with details upon failure. #### Response Example (Success) ```json { "result": 1 } ``` #### Response Example (Failure) ```json { "error": "Error: exceeded maximum of 256 characters" } ``` ``` ```APIDOC ## GET /wallet/username ### Description Returns a `string` with the name of the `wallet` to which this subwallet belongs. ### Method GET ### Endpoint /wallet/username ### Parameters #### Path Parameters None #### Query Parameters - **subWalletUser** (string) - Required - The identifier for the subwallet. ### Request Example ```http GET /wallet/username?subWalletUser=user123 ``` ### Response #### Success Response (200) - **username** (string) - The name of the wallet associated with the subwallet. #### Failure Response (Error String) - **error** (string) - Returns a string with details upon failure. #### Response Example (Success) ```json { "username": "primary_wallet" } ``` #### Response Example (Failure) ```json { "error": "Unknown error: Unable to access to local computer" } ``` ``` -------------------------------- ### Get Reverse Shell Server Source: https://documentation.greyscript.org/index Returns a list of shell objects connected to this computer via reverse shell. Requires the 'rshell' service to be installed on the receiving machine. Returns `null` if the provided object is not a metaxploit object. ```APIDOC ## GET /rshell/server/connections ### Description Returns a list of shell objects connected to this computer via reverse shell. Requires the 'rshell' service to be installed on the receiving machine. Returns `null` if the provided object is not a metaxploit object. ### Method GET ### Endpoint `/rshell/server/connections` ### Parameters #### Path Parameters None #### Query Parameters - **metaxploit** (object) - Required - The metaxploit object. ### Request Example `GET /rshell/server/connections?metaxploit=metaxploit_object_identifier` ### Response #### Success Response (200) - **shells** (list) - A list of active reverse shell connections. #### Error Response (400 or 500) - **error** (string) - Returns a string with details of the error. #### Response Example (Success) ```json { "shells": [ "shell_object_1", "shell_object_2" ] } ``` #### Response Example (Error) ```json { "error": "rshell_server: No internet connection" } ``` ``` -------------------------------- ### Get File Size Source: https://documentation.greyscript.org/index Returns the size of a file in bytes as a string. The size is dependent on the filename, not content. Returns null if the file is deleted. Example checks if the size exceeds 1000 bytes using an FTP connection. ```greyscript shell = get_shell ftpShell = shell.connect_service("172.8.0.5", 21, "test", "test", "ftp") ftpComputer = ftpShell.host_computer lsBinary = ftpComputer.File("/bin/ls") size = lsBinary.size if size.to_int > 1000 then print("File size is bigger than 1000 bytes.") else print("File size is below 1000 bytes.") end if ``` -------------------------------- ### Class and Object Instantiation (Greyscript) Source: https://documentation.greyscript.org/index Demonstrates the creation of classes and objects in Greyscript using a map-based approach with a special '__isa' entry for inheritance. Shows how to define a base class and create instances with properties. ```greyscript Shape = { "sides": 0 } Square = new Shape Square.sides = 4 x = new Square print(x.sides) // 4 ``` -------------------------------- ### Get PIN with Greyscript Source: https://documentation.greyscript.org/index Returns a periodically refreshing PIN string used for cryptocurrency service account access. Returns a string on success, or a string with error details on failure. Includes example code for interacting with the file system and blockchain. ```greyscript blockchain = include_lib("/lib/blockchain.so") myShell = get_shell myComputer = myShell.host_computer wallet = blockchain.login_wallet("test", "test") myComputer.touch("/root", "pin_launch.src") myFile = myComputer.File("/root/pin_launch.src") myFile.set_content("\ blockchain = include_lib(\"/lib/blockchain.so\") ") ``` -------------------------------- ### Get File Permissions Source: https://documentation.greyscript.org/index Retrieves the permissions of a file as a formatted string. Returns null if the file is deleted. The format includes file type (directory 'd' or file '-') and read/write/execute permissions for user, group, and others. Example format: '-rwxr-xr-x'. Demonstrated with an FTP connection. ```greyscript shell = get_shell ftpShell = shell.connect_service("172.8.0.5", 21, "test", "test", "ftp") ftpComputer = ftpShell.host_computer binFolder = ftpComputer.File("/bin") permissions = binFolder.permissions fileType = permissions[0] permissionsForUser = permissions[1:4] permissionsForGroup = permissions[4:7] permissionsForOther = permissions[7:10] print("File type: " + fileType) print("User permissions: " + permissionsForUser) print("Group permissions: " + permissionsForGroup) print("Other permissions: " + permissionsForOther) ``` -------------------------------- ### Show Packages in Repository using APT Client Source: https://documentation.greyscript.org/index Displays all packages and their descriptions within a specified repository, which must be listed in '/etc/apt/sources.txt'. Returns a string of packages on success or an error message on failure. Returns null if the repository value is not a string. Requires '/lib/aptclient.so'. ```greyscript aptClient = include_lib("/lib/aptclient.so") packages = aptClient.show("177.202.15.132") packageList = packages.split(char(10) + char(10)) packageList.pop // remove last empty item for packageItem in packageList entry = packageItem.split(char(10)) packageName = entry[0] packageDescription = entry[1] print "Title: " + packageName + "" print "Description: " + packageDescription + "" print "----------------------------" end for ``` -------------------------------- ### Get Current Date and Time Source: https://documentation.greyscript.org/index Retrieves the current in-game date and time as a formatted string. The in-game clock runs 15 times faster than real-time. The game starts on January 1st, 2000, 6:00 AM, and time does not advance when the server is offline. The output format is '[day]/[month]/[year] - [hours]:[minutes]'. ```greyscript dateStr = current_date dateSegments = dateStr.split(" - ") date = dateSegments[0].split("/") day = date[0] month = date[1] year = date[2] dateTime = dateSegments[1].split(":") hours = dateTime[0] minutes = dateTime[1] print("Current day: " + day) ``` -------------------------------- ### Launch Program with Parameters Source: https://documentation.greyscript.org/index Launches an executable binary with optional parameters. Returns 1 on success, 0 on failure, or an error string. There's a 2-second cooldown between launches. ```greyscript shell = get_shell("root", "test") launch(shell, "/bin/cat", "/etc/passwd") ``` -------------------------------- ### aptClient.show Source: https://documentation.greyscript.org/index Displays all packages available in a specified repository. Requires the repository to be listed in '/etc/apt/sources.txt'. Returns a string of packages or null if the repository is not found or input is invalid. ```APIDOC ## GET /apt/show ### Description Show displays all the packages available in a repository. The repository must be listed in the `"/etc/apt/sources.txt"` file. If the provided repository value is anything other than a `string`, this method will return `null`. If it cannot find a repository, it will return various error messages. On success, it will return a `string` containing all packages and their descriptions, with each entry separated by a newline. ### Method GET ### Endpoint /apt/show ### Parameters #### Query Parameters - **repository** (string) - Required - The name or IP address of the repository to query. ### Request Example ```json { "repository": "177.202.15.132" } ``` ### Response #### Success Response (200) - **packages** (string) - A string containing all packages and their descriptions within the specified repository, with entries separated by double newlines. #### Error Response (400) - **error** (string) - Returns an error message if the repository is not found or the input is invalid. #### Response Example ```json { "packages": "packageA\nDescriptionA\n\npackageB\nDescriptionB" } ``` ``` -------------------------------- ### Display Repository Packages Source: https://documentation.greyscript.org/index Shows all available packages within a specified repository. The repository must be listed in '/etc/apt/sources.txt'. Returns a string of package information on success, an error string if the repository is not found, or null for invalid parameter types. Requires the aptClient library. ```greyscript aptClient = include_lib("/lib/aptclient.so") packages = show(aptClient, "177.202.15.132") packageList = split(packages, char(10) + char(10)) pop(packageList) // remove last empty item for packageItem in packageList entry = split(packageItem, char(10)) packageName = entry[0] packageDescription = entry[1] print "Title: " + packageName + "" print "Description: " + packageDescription + "" print "----------------------------" end for ``` -------------------------------- ### Get File Path Source: https://documentation.greyscript.org/index Retrieves the full path of the file. If the file is a symbolic link, an optional argument can be provided to get the original path of the linked file. The path is returned even if the file has been deleted. ```greyscript hostComputer = get_shell.host_computer passwdFile = hostComputer.File("/etc/passwd") print("File location: " + passwdFile.path) ``` -------------------------------- ### Show Packages in Repository API Source: https://documentation.greyscript.org/index Displays all the packages available in a repository. The repository must be listed in the "/etc/apt/sources.txt" file. On success, it will return a string containing all packages and their descriptions, with each entry separated by a newline. ```APIDOC ## GET /show ### Description Displays all the packages available in a repository. The repository must be listed in the "/etc/apt/sources.txt" file. On success, it will return a string containing all packages and their descriptions, with each entry separated by a newline. ### Method GET ### Endpoint /show ### Parameters #### Query Parameters - **repository** (string) - Required - The repository to show packages from. ### Request Example ```json { "repository": "177.202.15.132" } ``` ### Response #### Success Response (200) - **packages** (string) - A string containing all packages and their descriptions, separated by newlines. #### Error Response (string) - **error** (string) - Returns an error message if the repository is not found or if there's an issue accessing the package list. #### Response Example ```json { "packages": "package1\nDescription for package1\n\npackage2\nDescription for package2" } ``` ``` -------------------------------- ### launch Source: https://documentation.greyscript.org/index Launches an executable binary located at the specified path, with optional command-line parameters. Returns 1 (success) or 0 (failure) as a number, or a string with an error message. Note that this is a synchronous operation, and there's a 2-second cooldown between launches. ```APIDOC ## POST /launch ### Description Launches a binary executable from a given path, optionally with parameters. Returns a number: 1 for success, 0 for failure. May also return a string with an error message. The operation is synchronous, pausing script execution until completion. A 2-second cooldown is enforced between launches. ### Method POST ### Endpoint /launch ### Parameters #### Request Body - **program** (string) - Required - The absolute path to the binary to launch. - **params** (string) - Optional - Command-line parameters to pass to the program. ### Request Example ```json { "program": "/bin/cat", "params": "/etc/passwd" } ``` ### Response #### Success Response (200) - **result** (number | string) - Returns 1 if the launch is successful. May return 0 or an error string if the launch fails or is within the cooldown period. #### Response Example ```json { "result": 1 } ``` ``` -------------------------------- ### Add APT Repository Source: https://documentation.greyscript.org/index Adds a repository to the '/etc/apt/sources.txt' file. Returns an empty string on success, a string with an error message on failure, or null if parameter types are incorrect. Errors include inability to access local computer, missing sources.txt, repository already added, or malformed sources.txt content. ```greyscript aptClient = include_lib("/lib/aptclient.so") ``` -------------------------------- ### Parent Directory Source: https://documentation.greyscript.org/index Get the parent directory of the current file. ```APIDOC ## Parent Directory ### parent() #### Description Returns the parent `ftpFile` object of the current file. In case the file is at the root directory, this method will return `null`. #### Method *Implicit* #### Endpoint `File.parent` #### Example ```lua shell = get_shell ftpShell = shell.connect_service("172.8.0.5", 21, "test", "test", "ftp") ftpComputer = ftpShell.host_computer passwdFile = ftpComputer.File("/etc/passwd") parentDir = passwdFile.parent if parentDir then print("Parent directory name: " .. parentDir.name) else print("This file is in the root directory.") end if ``` ``` -------------------------------- ### connect_ethernet(computer, netDevice, localIp, gateway) Source: https://documentation.greyscript.org/index Sets up a new IP address on a computer via ethernet. Requires appropriate permissions. Returns an empty string on success, or a string with error details/null on failure. ```APIDOC ## connect_ethernet(self: computer, netDevice: string, localIp: string, gateway: string) ### Description Sets up a new IP address on the `computer` through the ethernet connection. It is not possible to set up a new IP address while being logged in as a guest. On failure, this method will either return a `string` with details or `null`. On success, it will return an empty `string`. If any of the provided parameters have a type that deviates from the defined signature or the computer is not connected to the internet, an error will be thrown preventing any further script execution. ### Method N/A (Method Call) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Instance Parameters - **self** (computer) - The computer object. - **netDevice** (string) - The network device name (e.g., "eth0"). - **localIp** (string) - The desired local IP address. - **gateway** (string) - The gateway address for the network. ### Request Example ```greyScript computer = host_computer(get_shell) connectionResult = connect_ethernet(computer, "eth0", "192.168.0.4", local_ip(get_router)) if typeof(connectionResult) == "string" then print("There was an error while connecting: " + connectionResult) else print("Connected successfully.") end if ``` ### Response #### Success Response ("", empty string) Returns an empty string on successful connection setup. #### Error Response - **string** - Details of the error (e.g., "Error: Ethernet card not connected to the network", "Unable to find ISP network to connect using Ethernet card", etc.). - **null** - If parameter types do not match the signature or the computer is not connected to the internet. #### Response Example ```json "" ``` ``` -------------------------------- ### Get String Length Source: https://documentation.greyscript.org/index Returns a number representing the length of the string. ```Greyscript myString = "HELLO WORLD" print("Size of string is: " + myString.len) ``` -------------------------------- ### Add APT Repository Source: https://documentation.greyscript.org/index Adds a repository to the '/etc/apt/sources.txt' file. It validates input types and returns a string indicating success (empty string) or an error message on failure. Incorrect inputs may result in a null return. ```APIDOC ### add_repo( self: aptClient, repository: string, port: number = 1542 ): stringornull ### Description Adds a repository address to the `"/etc/apt/sources.txt"` file. If any of the provided parameters have a type that deviates from the defined signature, the method will return `null`. On success, it will return an empty `string`. In case of failure, it will return a `string` with an error message. ### Method N/A (Function) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **self** (aptClient) - Required - The aptClient object. * **repository** (string) - Required - The repository address to add. * **port** (number) - Optional - The port number for the repository. Defaults to 1542. ### Request Example ```javascript aptClient = include_lib("/lib/aptclient.so") result = aptClient.add_repo("http://example.com/repo", 8080) if result == "" then print("Repository added successfully.") else print("Error adding repository: " + result) end if ``` ### Response #### Success Response (200) * **result** (string) - An empty string indicates success. #### Error Response (400/500) * **result** (string) - A string containing the error message on failure. #### Response Example ```json { "result": "" } ``` #### Error Response Example ```json { "result": "/etc/apt/sources.txt does not exist" } ``` ``` -------------------------------- ### String: Get Unicode Code Source: https://documentation.greyscript.org/index Returns the Unicode code of the first character of a string. ```Greyscript myString = "HELLO WORLD" print(myString.code) ``` -------------------------------- ### Start a Service Source: https://documentation.greyscript.org/index Initiates a service. The return value can be a number, string, or null, indicating success or the reason for failure. Specific error messages are provided for permission issues or service unavailability. ```greyscript start_service(service) # Example output messages: # "Denied. Only root user can install this service." # "${reason} The chat service can't be accessed." # 1 (indicating success or a specific status code) ``` -------------------------------- ### Get Number of User Accounts Source: https://documentation.greyscript.org/index Retrieves the total number of user accounts on the system. ```APIDOC ## Get Number of User Accounts ### Description Returns the total number of user accounts configured on the system. ### Method GET (implied by get_num_users) ### Endpoint `/websites/greyscript` (context) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript metax = include_lib("/lib/metaxploit.so") ports = get_router("1.1.1.1").used_ports netSession = metax.net_use("1.1.1.1", ports[0].port_number) print("User accounts: " + netSession.get_num_users) ``` ### Response #### Success Response (200) - **num_users** (number) - The count of user accounts. #### Response Example ```json { "num_users": 10 } ``` ``` -------------------------------- ### Launch Program with Parameters in Greyscript Source: https://documentation.greyscript.org/index Launches a binary executable from a given path, optionally with parameters. Returns `1` for success and `0` for failure or if launched during a 2-second cooldown. Can return an error string in certain cases. Execution is synchronous. Runtime exceptions are thrown for signature deviations. Consider `get_custom_object` for inter-process variable sharing. ```greyscript shell = get_shell("root", "test") shell.launch("/bin/cat", "/etc/passwd") ``` -------------------------------- ### Get File Name Source: https://documentation.greyscript.org/index Retrieves the name of the file. Returns null if the file has been deleted. ```greyscript hostComputer = get_shell.host_computer passwdFile = hostComputer.File("/etc/passwd") print("Filename: " + passwdFile.name) ``` -------------------------------- ### Get Library Name Source: https://documentation.greyscript.org/index Retrieves the name of a library. Returns null for invalid metaLib objects. ```greyscript metax = include_lib("/lib/metaxploit.so") metaLib = load(metax, "/lib/init.so") print("Name for library is: " + lib_name(metaLib)) ``` -------------------------------- ### Get Active User Source: https://documentation.greyscript.org/index Returns the username of the currently executing script's user as a string. ```greyscript print("Current active user: " + active_user) ``` -------------------------------- ### Search for Packages using APT Client Source: https://documentation.greyscript.org/index Searches for packages matching a string in repositories listed in '/etc/apt/sources.txt'. Returns a string of matching packages on success or an error message on failure. Returns null if the search value is not a string. Requires '/lib/aptclient.so'. ```greyscript aptClient = include_lib("/lib/aptclient.so") packages = aptClient.search(".so") packageList = packages.split(char(10) + char(10)) for packageItem in packageList entry = packageItem.split(char(10)) if entry.len != 2 then print "something wrong in: " + entry continue end if packageName = entry[0] packageDescription = entry[1] print "Title: " + packageName + "" print "Description: " + packageDescription + "" print "----------------------------" end for ``` -------------------------------- ### Get File Name - Greyscript Source: https://documentation.greyscript.org/index Retrieves the name of the file. Returns null if the file has been deleted. ```Greyscript shell = get_shell ftpShell = shell.connect_service("172.8.0.5", 21, "test", "test", "ftp") ftpComputer = ftpShell.host_computer passwdFile = ftpComputer.File("/etc/passwd") print("Filename: " + passwdFile.name) ``` -------------------------------- ### Create Folder API Source: https://documentation.greyscript.org/index Creates a new folder at the specified path on the computer. ```APIDOC ## POST /create_folder ### Description Creates a new folder at the specified path on the computer. ### Method POST ### Endpoint /create_folder ### Parameters #### Path Parameters - None #### Query Parameters - **path** (string) - Required - The path where the new folder should be created. - **folder** (string) - Optional - The name of the new folder. Defaults to 'newFolder'. #### Request Body - None ### Request Example ```javascript // Example using a JavaScript-like syntax for demonstration const computer = host_computer(get_shell()); const createResult = create_folder(computer, "/home/user/documents", "myNewFolder"); if (typeof createResult === "string") { console.log("Error creating folder: " + createResult); } else { console.log("Folder created successfully."); } ``` ### Response #### Success Response (200) - **string or number or null** - Typically returns '1' on success, or a string with error details on failure. Can return null under specific error conditions. #### Response Example ```json { "result": 1 } ``` ``` -------------------------------- ### build Source: https://documentation.greyscript.org/index Compiles a plain code file provided in the arguments to a binary. On success, the new binary will be available under the provided build folder. ```APIDOC ## POST /build ### Description Compiles a plain code file provided in the arguments to a binary. On success, the new binary will be available under the provided build folder. The binary name will be the same as the source file just without the file extension. Optionally, an `allowImport` flag can be set which enables the use of `import_code` on the binary. All provided paths must be absolute. ### Method POST ### Endpoint /build ### Parameters #### Request Body - **shell** (object) - Required - The shell object. - **pathSource** (string) - Required - The absolute path to the source code file. - **pathBinary** (string) - Required - The absolute path to the directory where the binary will be created. - **allowImport** (number) - Optional - Flag to allow import_code (0 or 1). Defaults to 0. ### Request Example ```json { "shell": { /* ... */ }, "pathSource": "/home/user/test.src", "pathBinary": "/home/user/bin", "allowImport": 1 } ``` ### Response #### Success Response (200) - **result** (string) - An empty string on success. #### Error Response (non-200) - **error** (string) - A string containing details about the reason for failure. #### Response Example (Success) ```json { "result": "" } ``` #### Response Example (Failure) ```json { "error": "Can't find /home/user/test.src" } ``` ``` -------------------------------- ### Control Wi-Fi Monitor Mode with Airmon Source: https://documentation.greyscript.org/index Enables or disables monitor mode on a network device. 'start' activates monitor mode, while 'stop' deactivates it. Monitor mode is only supported on Wi-Fi cards. Dependencies: crypto library, airmon. Inputs: crypto object, option ('start' or 'stop', string), device name (string). Outputs: 1 on success (number), 0 or error message (number or string) on failure. ```greyscript crypto = include_lib("/lib/crypto.so") airmonResult = airmon(crypto, "start", "wlan0") if typeof(airmonResult) == "string" then print("There was an error while switching monitoring mode: " + airmonResult) else print("Monitoring mode switched successfully.") end if ``` -------------------------------- ### Search Packages using Apt Client Source: https://documentation.greyscript.org/index Searches for packages in APT repositories based on a search string. Returns a string of matching packages or an error message. Returns null if parameter types are incorrect. Requires the APT cache to be up-to-date. ```Greyscript aptClient = include_lib("/lib/aptclient.so") packages = search(aptClient, ".so") packageList = split(packages, char(10) + char(10)) for packageItem in packageList entry = split(packageItem, char(10)) if len(entry) != 2 then print "something wrong in: " + entry continue end if packageName = entry[0] packageDescription = entry[1] print "Title: " + packageName + "" print "Description: " + packageDescription + "" print "----------------------------" end for ``` -------------------------------- ### Get All Indexes of Characters Source: https://documentation.greyscript.org/index Returns a list of numbers, where each number is an index where a specific character appears in the string. ```Greyscript myString = "42" print(myString.indexes) ``` -------------------------------- ### Add Repository to APT Client Source: https://documentation.greyscript.org/index Adds a software repository to the APT client. It checks the result of the operation and prints a success or error message. Dependencies include an initialized APT client object. Inputs: aptClient (object), repository address (string). Outputs: Success or error message (string). ```greyscript result = add_repo(aptClient, "177.202.15.132") if result == "" then print "Addition successful!" else print "Error while adding: " + result end if ``` -------------------------------- ### Add Repository using aptClient in GreyScript Source: https://documentation.greyscript.org/index Inserts a repository address into the "/etc/apt/sources.txt" file using the aptClient library. It returns an empty string on success, a string with an error message on failure, or null if parameter types are incorrect. Dependencies include the aptclientLib. ```greyscript aptClient = include_lib("/lib/aptclient.so") result = aptClient.add_repo("177.202.15.132") if result == "" then print "Addition successful!" else print "Error while adding: " + result end if ``` -------------------------------- ### Map: Get All Keys Source: https://documentation.greyscript.org/index Returns a list containing all keys present in the map. Keys can be of any data type. ```greyscript myMap = { "answer": 42, "bar": 23, "foo": "moo" } for key in myMap.indexes print(myMap[key]) end for ``` -------------------------------- ### Launch Reverse Shell Client in Greyscript Source: https://documentation.greyscript.org/index Initiates a reverse shell client process on a target computer, attempting to connect to a specified IP address and port. Requires the 'rshell' service to be installed and port forwarding configured. Returns '1' on success, or a string with error details on failure. IP addresses and process names have validation rules. ```greyscript metax = include_lib("/lib/metaxploit.so") rshell_client(metax, "1.1.1.1", 1222, "bgprocess") ``` -------------------------------- ### List: Get Length Source: https://documentation.greyscript.org/index Returns the number of elements in a list. This is a common operation for determining the size of a list. ```greyscript myList = [42, 1, 3] print("myList contains " + myList.len + " items") ``` -------------------------------- ### Create and manage groups in Greyscript Source: https://documentation.greyscript.org/index Demonstrates creating a new group and retrieving existing groups for a specified user on a host computer. It involves obtaining a shell connection, creating a group, and then listing all groups associated with the 'root' user. ```greyscript computer = host_computer(get_shell("root", "test")) create_group(computer, "root", "staff") groups = groups(computer, "root") listOfGroups = groups.split(char(10)) print(listOfGroups) ``` -------------------------------- ### Get Mathematical Constant PI Source: https://documentation.greyscript.org/index Returns the numerical value of PI with a precision of six decimal places. ```greyscript radius = 10 circumference = 2 * pi * radius print("Circumference: " + circumference) ``` -------------------------------- ### Get Computer Hostname Source: https://documentation.greyscript.org/index Retrieves the hostname of the machine. Returns 'Unknown' if an invalid computer object is provided. ```greyscript computerName = get_name(host_computer(get_shell)) print("The name of your machine is " + computerName) ``` -------------------------------- ### Compile Code to Binary with Greyscript Source: https://documentation.greyscript.org/index Compiles a plain code file into a binary. The binary is saved in the specified build folder with the same name as the source file (without extension). Optionally enables import functionality. Requires absolute paths for all inputs. Returns an empty string on success or an error message on failure. Runtime exceptions are thrown for signature deviations. ```greyscript shell = get_shell computer = shell.host_computer computer.touch(home_dir, "test.src") computer.File(home_dir + "/test.src").set_content("print(\"hello world\")") buildResult = shell.build(home_dir + "/test.src", home_dir + "/Desktop") if buildResult != "" then print("There was an error while compiling: " + buildResult) else print("File has been compiled.") end if ``` -------------------------------- ### File Path Utilities Source: https://documentation.greyscript.org/index Provides methods to get file paths, including handling symlinks and deleted files. ```APIDOC ## File Path Utilities ### path() Returns a `string` containing the file path. If the file is a symlink, the optional `symlinkOrigPath` argument can be set to return the original path of the linked file instead. If the file has been deleted, this method will still return the path it had prior to deletion. If an invalid `file` object is passed, this method will return `null`. ### Method `path(self: file, symlinkOrigPath: number = 0): stringornull` ### Example ``` computer = host_computer(get_shell) passwdFile = File(computer, "/etc/passwd") print("File location: " + path(passwdFile)) ``` ``` -------------------------------- ### POST /create_user Source: https://documentation.greyscript.org/index Creates a new user on the computer with a specified username and password. Root access is mandatory, and both username and password have character and alphanumeric restrictions. ```APIDOC ## POST /create_user ### Description Creates a user on the computer with the specified name and password. Root access is required. Username and password must be alphanumeric and no more than 15 characters each. There's a system-wide limit of 15 users. ### Method POST ### Endpoint /create_user ### Parameters #### Query Parameters - **username** (string) - Required - The desired username. Must be alphanumeric and max 15 characters. - **password** (string) - Required - The desired password. Must be alphanumeric and max 15 characters. ### Request Example ```json { "username": "newUser", "password": "123" } ``` ### Response #### Success Response (200) - **result** (number) - Returns 1 on successful creation. #### Error Response (400) - **error** (string) - Returns a string detailing the reason for failure (e.g., root user exists, invalid characters, user already exists, limit reached). #### Response Example (Success) ```json { "result": 1 } ``` #### Response Example (Failure) ```json { "error": "Error: can't create user. newUser already exists." } ``` ``` -------------------------------- ### Get Length of Data Type Source: https://documentation.greyscript.org/index Returns the size of a string, list, or map. Returns null for other data types. ```greyscript length = len("test") print("Length of string is: " + length) ``` -------------------------------- ### Compile Code to Binary Source: https://documentation.greyscript.org/index Compiles a source code file into a binary executable. Supports an optional flag to allow importing. Requires absolute paths for source and binary destination. Returns an empty string on success or an error message on failure. ```Greyscript shell = get_shell computer = host_computer(shell) touch(computer, home_dir, "test.src") set_content(File(computer, home_dir + "/test.src"), "print(\"hello world\")") buildResult = build(shell, home_dir + "/test.src", home_dir + "/Desktop") if buildResult != "" then print("There was an error while compiling: " + buildResult) else print("File has been compiled.") end if ``` -------------------------------- ### Get Executed Script Path Source: https://documentation.greyscript.org/index Returns the path of the initially executed script, even when using the 'launch' function. ```greyscript path = launch_path print("Script gets executed within: " + parent_path(path)) ``` -------------------------------- ### aptClient.search Source: https://documentation.greyscript.org/index Searches for a package in repositories listed in '/etc/apt/sources.txt'. Returns a string of matching packages or null if the input is invalid. ```APIDOC ## GET /apt/search ### Description Searches specifically for a package in any of the repositories listed in `"/etc/apt/sources.txt"`. If the provided search value is anything other than a `string`, this method will return `null`. On success, it will return a `string` containing all packages that partially match the provided search value. On failure, it will return a `string` with various error messages. ### Method GET ### Endpoint /apt/search ### Parameters #### Query Parameters - **search** (string) - Required - The string to search for in package names. ### Request Example ```json { "search": ".so" } ``` ### Response #### Success Response (200) - **packages** (string) - A string containing all packages that partially match the search value, with entries separated by double newlines. #### Error Response (400) - **error** (string) - Returns an error message if the search fails or input is invalid. #### Response Example ```json { "packages": "package1\nDescription1\n\npackage2\nDescription2" } ``` ``` -------------------------------- ### Search Package API Source: https://documentation.greyscript.org/index Searches for packages in APT repositories based on a search string. Returns a string with matching package names and descriptions on success, or an error message string on failure. Returns null if parameter types are incorrect. ```APIDOC ## GET /search ### Description The `search` method specifically looks for a package in any of the repositories listed in `"/etc/apt/sources.txt"`. If any of the provided parameters have a type that deviates from the defined signature, the method will return `null`. On success, it will return a `string` containing all packages that partially match the provided search value. On failure, it will return a `string` with various error messages. ### Method GET ### Endpoint /search ### Parameters #### Query Parameters - **search** (string) - Required - The string to search for in package repositories. ### Request Example ``` GET /search?search=.so ``` ### Response #### Success Response (200) - **packages** (string) - A string containing package names and descriptions that match the search query. #### Response Example ```json { "packages": "package1\nDescription for package1\n\npackage2\nDescription for package2" } ``` ``` -------------------------------- ### Get Kernel Router Version Source: https://documentation.greyscript.org/index Retrieves the version of the kernel_router.so library. Returns null if the input is not a router object. ```greyscript router = get_router version = kernel_version(router) print("Kernel router version: " + version) ```