Andrey Nikitin
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • Create new note
      • Create a note from template
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Write
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Save as template
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Below I will briefly explain the common vulnerabilities that are addressed by the scripts in this repo. Although scripts are very useful, they can not anticipate everything. These descriptions will come in handy when you need to manually threat hunt your system. You can always reference [hacktricks](https://book.hacktricks.wiki/en/linux-hardening/linux-privilege-escalation-checklist.html) for a more thorough checklist. ## Table of Contents ### Running Scripts [Linux Scripts](##Linux-Scripts) [Windows Scripts](##Windows-Scripts) ### Linux Vulns [System](#System) - [PAM](##PAM) - [Cron jobs](##Cron-jobs) - [Set-uid/gid](##Set-uid/gid) - [Path hijacking](##Path-hijacking) - [Shared libraries](##Shared-libraries) - [Symbolic linking](##Symbolic-linking) - [Restricted environmennts](##Restricted-environments) - [User](##User) - [ACLs](##ACLs) - [Capabilities](##Capabilities) [Services](#Services) - [SSH](##SSH) ### Linux Benchmarks [AppArmor](#AppArmor) ### Windows Vulns ### Windows Benchmarks # Linux Scripts To get the scripts you can run `git clone https://github.com/pyukey/Vuln-Scripts.git`. However, many machines may not have git, so instead I will scp the files to you. ## rollPasswd.sh First you should ``` cd Vuln-Scripts/Linux sudo ./rollPasswd.sh ``` - If you see `New password: Retype new password:` that means that passwords were changed using `passwd` whcich **could be backdoored**. Check by running `which passwd` and then inspecting that binary. - **Save these passwords somewhere**. Copy+paste in chat. If you lose access to the machine then you're cooked. - **Make sure to update scoring services with the new passwds** ## backup.sh Backups are optional. Run `sudo ./backup.sh` and it will make the backup (you will need to provide a passwd to encrypt the backup with). To retrieve, run ``` gpg -d /opt/.bk.tar.gz.gpg tar -xzvf /opt/.bk.tar.gz ``` ## userHardening ``` cd userHardening ./fixUsers.sh ``` These will enumerate all users on the system and prompt you for each vulnerability it finds. - If you answer `y` it applies the change, anything else is ignored. - If you're not sure if a user is needed check `essentialUsers.txt`. You should NOT mess with these. Then check `serviceUsers.txt`. These users are optional depending on what services you are running. If you want to see all the users on your system [displayed nicely](##User), run `sudo ./listUsersColor.sh` ## firewall.sh Having a firewall isn't *that* important, so do this when you feel comfortable. ``` sudo ./firewall.sh [ad] [web] [ftp] [#] ``` - Depending on your machine, you will need allow certain services through the firewall. Do listing the ports as arguments. For example, `sudo ./firewall.sh ad 1337 8080` would allow traffic for AD and on port 1337 and 8080. - By default, icmp, ssh (22) and dns (53) are allowed. If you need to access the internnet, include `web` - If you have AD users, include `ad` **DON'T GET BURNED BY THE FIREWALL!** If your services go down after running this, flush your rules with `sudo iptables -F` and think carefully. ## blackout.sh Consider this scenario: your system is cooked, you have a 20+ active ssh connections, how can you deal with it all?! This script is a **last resort for total isolation!** It blocks by ip so only *you* can access the network. If you screwed up, no worries the script fixes itself. Your terminal will probably be frozen, so just open a new terminal and ssh from there. ``` sudo iptables -F sudo ./balckout.sh ``` ## Next Steps 1. Secure your services 2. Check `.bash_history` to see if red team left any traces 3. Check [PAM](##Pam) by looking at `/etc/pam.d/common-auth`, `/etc/pam.d/su`, and maybe `/etc/pam.d/password-auth`. You also want to check if `/lib/x86_64-linux-gnu/security/pam_deny.so` has been backdoored with `pam_permit.so` by using `./checkSum.sh <file1> <file2>` 4. Run [lse.sh](https://github.com/diego-treitos/linux-smart-enumeration/tree/master) or [LinPEAS](https://github.com/peass-ng/PEASS-ng/tree/master/linPEAS) and address threats. 5. See if PATH has been [hijacked](##Path-hijacking) by running `echo $PATH`. Make sure to also switch to root user and check! 6. Run the yara rules to look for malicious binaries `yara <rule> -r <directory-to-scan>` # Windows Scripts See W section (pg 39) of the cheatsheet. Your goals should be: 1. Change passwords 2. Force credentials reset (e.g. Kerberos tokens) 3. Run sysinternals for threat detection # System ## PAM PAM handles authentication in Linux and consists of config files in `/etc/pam.d`, which reference so files in `/lib/x86_64-linux-gnu/security/`. You can read more [here](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/managing_smart_cards/pam_configuration_files). The most relevant config files are (with examples): - `password-auth` (RHEL-based) and `common-auth` (Debian-based): handles authentication stuff ``` password [success=1 default=ignore] pam_unix.so obscure yescrypt password requisite pam_deny.so password required pam_permit.so ``` - `su` handles who can su ``` # If you want root to su w/o passwd then it should begin with auth sufficient pam_rootok.so ``` - `common-password` for changing passwords ``` # Optional line if you're enforcing passwd policy password requisite pam_pwquality.so retry=3 minlen=12 difok=3 # If succeeds, skip next line (so jumps to permit). The yescrypt is secure hashing algorithm password [success=1 default=ignore] pam_unix.so obscure yescrypt password requisite pam_deny.so password required pam_permit.so ``` Each line in these config files will consist of an interface: - `auth`: authentication - `account`: authorization (expired, time of day) - `password`: changing passwd - `session`: other stuff during login/logout a flag: - `required` must succeed. - `requisite` must succeed and notifies immediately of first fail - `sufficient` if succeeds (and no previous fails), then you pass - `optional` only necessarry if there are no other modules - `include` and a module: - `pam_console.so`: checks for `/etcc/security/console.apps` file - `pam_cracklib.so`: checks new passwds against dictionary attack - `retry=#` number of retries allowed- `pam_permit.so`: allows login - `pam_deny.so`: denies login - `pam_nologin.so`: fails if `/etc/nologin` exists and uid != 0 - `pam_rootok.so`: checks if uid=0 - `pam_securetty.so`: if logging in as root, check if tty is in `/etc/securetty` - `pam_unix.so`: prompts and compares password to `/etc/shadow` - `nullok`: allows blank passwd - `shadow`: when updating passwd, stores in `/etc/shadow` ## Cron-jobs Check these directories: - `/var/spool/` - `/etc/cron` stuff ## Set-uid/gid If this bit is set, then you execute the file with the permissions of the owner. Check [GTFOBins](https://gtfobins.github.io/) if it is exploitable. You can read more [here](https://tbhaxor.com/demystifying-suid-and-sgid-bits/). ## Path hijacking When you run a command like `ls`, the system checks your path from left to right to see if the file exists. If an attacker can place a directory they can write to at the start of your path, then they can put malicious executables there, which take priority over `/bin`. ## Shared libraries This is similar to Path hijacking for dynamically linked libraries. I don't understand it well so you can read more [here](https://tbhaxor.com/understanding-concept-of-shared-libraries/). It has something to do with `LD_PRELOAD` environmental variable. ## Symbolic linking If a priviledged program creates a file `filename` in a directory writable by the user, the user can create a symlink `filename` that points to whatever file they want. This gives them write access to their target fille! You can see examples [here](https://lettieri.iet.unipi.it/hacking/ch/5-symlink.pdf). ## Restricted environments To prevent users from escalating, you can place them inside a restricted environment. However, these are often easy to break out of. One type is the **restricted shells** like `rsh`, which you can read about [here](https://tbhaxor.com/breaking-out-of-restricted-shell-environment/). The other is a **chroot jail**, which limits what files you can accesss by changing your root directory. As long as you have access to: 1. A privileged shell 2. A program that can call **mkdir, chroot, chdir** You can escape the jail, as shown [here](https://tbhaxor.com/breaking-out-of-chroot-jail-shell-environment/). ## User You can check a lot of this by looking at `/etc/passwd`. If you want to learn more, [this blog](https://tbhaxor.com/linux-file-permissions/) is great. - if the passwd field is blank, then a user can login w/o a passwd! Additionally, if you set a passwd for that user, it is stored in `/etc/passwd` instead of `/etc/shadow` `/etc/shadow` is where encrypted passwds should be stored - `*` (Debian-based) or `!!` (RHEL-based) means a passwd has never been set while `!` means the account is locked. Either way, the user can't login `/etc/groups` lists the users in each group. This is referenced when checking group permissions for things like file access. You'll notice that the passwd field in this file also has `x`, which indicates a corresponding shadow file... `/etc/gshadow` contains the passwds for groups. This allows users to add themselves to a group using `newgrp` if they provide the passwd. If a user is listed under that group, they don't need the passwd to add themselves to that group. This should never be enabled, so all passwd should be `!` ![image](https://hackmd.io/_uploads/r1wcR9IGll.png) **UID = 0** means the user is effectively root The `/etc/sudoers` file specifies who can run programs as root using the `sudo` command. Each line in that file follows the format `<user> <hosts>=(<runas_user>:<runas_group>) <options>:<commands>` so `root ALL=(ALL:ALL) ALL` would allow root to run all commands on all hosts as any user/group - The `NOPASSWD` option is BAD. They can run sudo without passwd! - instead of a user you can specify a group like `%admin`. You can specify a number insteaad of name with `#` - `@includedir <dirpath>` adds any files in that path to `/etc/sudoers`. You shouldn't have anything in `/etc/sudoers.d/` There are certain groups that if a user is a part of, they can exploit to run anything effectively as root: - **sudo** (Debian-based) and **wheel** (RHEL-based) are typically included in `/etc/sudoers` file. Check `.bash_profile` for login shells `.bashrc` for non-login shells: - sus `alias` could be sued to backdoor command - Could run commands at login ## ACLs **Access control lists** (acls) are an *additional* set of *user-specific* permissions that you can assign to files. These don't appear normally in `ls -l` (you may see a `+`), so instead use `getfacl`. ## Capabilities Capabilities are another set of permissions you assign to *processes*. Root can do a LOT of things, so to follow the principle of least privilege, Linux has grouped root's privileges into **capabilties**. This can be confusing, so here is a [detailed guide](https://github.com/huntergregal/mimipenguin/tree/master) and [practical overview](https://github.com/huntergregal/mimipenguin/tree/master). # Services ## SSH ## FTP ## Docker ## Kubernetes # AppArmor

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully