Grey Hack

Grey Hack

Not enough ratings
Bash history & secure logs features
By Xaks32
This /bin/bash will both add bash history feature and keep your logs safe
   
Award
Favorite
Favorited
Unfavorite
How to
Copy and Paste the code below into the CodeEditor and then compile it,
after compilation make sure to remove your current /bin/bash and copy the new one:
  1. cd /home/your_usename/
  2. CodeEditor.exe
  3. -- Copy & Paste, then save and compile the code into /home/your_username/ --
  4. -- Go back to terminal --
  5. sudo rm /bin/bash
  6. sudo cp ./bash /bin/bash

Things to take in consideration:
  1. Bash history logs are written by default on the running user home directory "/home/username/" under the file ".bash_history".
  2. when 'bash_secure_log' is set to 'true', it will also save logs on /etc/bash (or whatever is set in 'r_secure_folder' var), normal users can not have access to this folder unless they get access to root. set 'r_pass' to your password if you want to keep this feature enabled.
  3. Not setting your sudo password in-script using the 'r_pass' var will disable bash_secure_log feature.
  4. If you want to use the bash_secure_log feature on a remote computer, make sure to either use the same password you've compiled the code with on the remote machine or disable bash_secure_log and/or re-compile with the new root/admin password of the remote machine by changing the 'r_pass' var on the script.
  5. Setting 'bash_history_log' to 'false' will completely disable the history log feature.


flag_init = 1
bash_secure_log = true //If set to 'true', then make sure to check 'r_pass' var and set your root password in it.
bash_history_log = true

//Function used for printing debug/error messages back to the user
//Can be easily disabled or enabled by either passing true/false values
//or just ommitting the 2nd parameter
print_debug = function(str_message, debug_print=false)
if ( debug_print == true ) then
print(str_message)
end if
end function

//A Rooted shell object must be passed to this function
//ex: r_shell = get_shell("root", r_pass)
// return_value = is_root(r_shell)
root_test_flag = true
root_one_time_only = false
is_root = function(r_shell)
debug_print = true
groupTest = "xaks32cbash"
cmdStr = "root" + " " + groupTest
is_root_v = false

if ( r_shell != null) then
root_groups_list = r_shell.host_computer.groups("root")
if(root_groups_list.len >= 1) then
for groups_v in root_groups_list.split("\n")
if (groups_v.len < 1) then break
if (groups_v == groupTest) then
is_root_v = true
break
end if
end for
end if
end if

//Only tests for 'root' once after group 'xaks32_cbash' has not been found
if ( is_root_v == false and globals.root_test_flag == true ) then
print_debug(" ", debug_print)
print_debug("---------------------------", debug_print)
print_debug("Setting up BASH_SECURE_LOGS.", debug_print)
if ( r_shell != null ) then
r_shell.launch("/bin/groupadd", cmdStr)
end if
globals.root_test_flag = false
is_root_v = is_root(r_shell)
if( is_root_v == true ) then
print_debug("Setup Completed!", debug_print)
end if
print_debug("---------------------------", debug_print)
else if ( is_root_v == false and globals.root_test_flag == false and globals.root_one_time_only == false) then
print_debug(" ", debug_print)
print_debug("Setup failed! secure_bash_logs will not be available!", debug_print)
print_debug("please check documentation:\n", debug_print)
print_debug(" https://gtm.steamproxy.vip/sharedfiles/filedetails/?id=3561712321", debug_print)
print_debug(" ", debug_print)
print_debug("---------------------------", debug_print)
globals.root_one_time_only = true
end if

return is_root_v
end function

bash_history = function(command, shell_arguments)
if (globals.bash_history_log == true) then
log_filename = ".bash_history"
log_file = "/home/" + active_user + "/" + log_filename
current_content = ""
if (active_user == "root") then
log_file = "/root/" + log_filename
end if

file = get_shell.host_computer.File(log_file)

//Create log_file if it doesn't exist
if (file == null) then
get_shell.launch("/bin/touch", log_file)
file = get_shell.host_computer.File(log_file)
end if

current_args = "[" + active_user + "] - " +
current_date + " - " + current_path + ":\n: " + command + " " +
shell_arguments + "\n---\n"

//If log_file hasn't failed to open, then set it's new contents:
if (file !=null) then
current_content = file.get_content + "\n"
current_content = current_content + current_args

file.set_content(current_content)
end if

if (globals.bash_secure_log == true) then
r_secure_folder = "/etc/bash"
r_hist_file = r_secure_folder + "/" + log_filename
r_pass = ""
r_shell = get_shell("root", r_pass)

if ( is_root(r_shell) == true ) then
r_file = r_shell.host_computer.File(r_hist_file)
r_folder = r_shell.host_computer.File(r_secure_folder)

//Creates 'r_secure_folder' if it's non-existing.
if (r_folder == null) then
r_shell.launch("/bin/mkdir", r_secure_folder)
r_folder = r_shell.host_computer.File(r_secure_folder)
end if


//Makes sure that file is created in case it has either been deleted or doesn't yet exists.
if (r_folder.is_folder == true) then
if (r_file == null) then
r_shell.launch("/bin/touch", r_hist_file)
r_file = r_shell.host_computer.File(r_hist_file)
end if
end if

if (r_file != null) then
//Checks whether permissions have changed, then change it back in case they've been modified
if (r_file.permissions != "-rwx------") then
r_shell.launch("/bin/chmod", "-R" + " " + "o-rwx" + " " + r_secure_folder)
r_shell.launch("/bin/chmod", "-R" + " " + "g-rwx" + " " + r_secure_folder)
end if

r_contents = r_file.get_content
r_contents = r_contents + current_args

r_file.set_content(r_contents)
else
print("\n--bash_secure_log disabled--\n")
end if
end if
end if
end if
end function

Bash = function()
if (flag_init == 1) then
globals.flag_init = 0
print("===========================================")
print("=============XAKS32 H@XX0R T3RM1N@L========")
print("===========================================")
else
print("\n===========================================")
end if

deviceName = get_shell.host_computer.get_name
promptCurrentFolder = deviceName + "]:" + current_path + "$"
if (active_user == "root") then
promptCurrentFolder = deviceName + "]:" + current_path + "#"
else if (current_path.indexOf(home_dir) != null) then
promptCurrentFolder = deviceName + "]:~"+ current_path.replace(home_dir, "") +"$"
end if

output = user_input("[" + active_user + "@" + promptCurrentFolder + "\n" +
current_date + "\n> ", false, false, true)
if(output.len == 0) then return

listCmd = output.trim.split(" ")
command = listCmd[0]
shellArgs = ""
if(listCmd.len > 1) then
listCmd.remove(0)
shellArgs = listCmd.join
end if

if(command == "exit") then exit
if(command == "clear") then
clear_screen
else
cmdPath = GetFinalPath(command)
print(" ") //Don't use a single " " instead of " "; will not add a new-line character when using 'sudo'
bash_history(command, shellArgs)
output = get_shell.launch(cmdPath, shellArgs)
if output and output != 1 then print(output)
end if
end function

GetFinalPath = function(command)
paths = [current_path, "/bin", "/usr/bin"]
for i in range(0, paths.len - 1)
if i == 0 then
absPath = get_abs_path(command)
else
absPath = paths[i] + "/" + command
end if
cmdFile = get_shell.host_computer.File(absPath)
if (cmdFile != null) then return absPath
end for
return command
end function

while(true)
Bash()
end while