Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7813393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:50:46+00:00 2026-06-02T04:50:46+00:00

I’m working on i386:x86_64 and I’m writing a simple program to start a shell.

  • 0

I’m working on i386:x86_64 and I’m writing a simple program to start a shell. Bellow is my assembly.

.section .data
.section .text
.globl _start

_start:
    xor %rax, %rax
    mov $70, %al
    xor %rbx, %rbx
    xor %rcx, %rcx
    int $0x80

    jmp ender

starter:
    pop %rbx
    xor %rax, %rax
    mov %al, 0x07(%rbx)
    mov %rbx, 0x08(%rbx)
    mov %rax, 0x0c(%rbx)
    mov $11, %al
    lea 0x08(%rbx), %rcx
    lea 0x0c(%rbx), %rdx
    int $0x80

ender:
    call starter
    .string "/bin/sh"

The problem is that I keep getting a segmentation fault. When I use objdump -D my_prog the output is this …

Disassembly of section .text:

0000000000400078 <_start>:
  400078:   48 31 c0                xor    %rax,%rax
  40007b:   b0 46                   mov    $0x46,%al
  40007d:   48 31 db                xor    %rbx,%rbx
  400080:   48 31 c9                xor    %rcx,%rcx
  400083:   cd 80                   int    $0x80
  400085:   eb 1b                   jmp    4000a2 <ender>

0000000000400087 <starter>:
  400087:   5b                      pop    %rbx
  400088:   48 31 c0                xor    %rax,%rax
  40008b:   88 43 07                mov    %al,0x7(%rbx)
  40008e:   48 89 5b 08             mov    %rbx,0x8(%rbx)
  400092:   48 89 43 0c             mov    %rax,0xc(%rbx)
  400096:   b0 0b                   mov    $0xb,%al
  400098:   48 8d 4b 08             lea    0x8(%rbx),%rcx
  40009c:   48 8d 53 0c             lea    0xc(%rbx),%rdx
  4000a0:   cd 80                   int    $0x80

00000000004000a2 <ender>:
  4000a2:   e8 e0 ff ff ff          callq  400087 <starter>
  4000a7:   2f                      (bad)  
  4000a8:   62                      (bad)  
  4000a9:   69                      .byte 0x69
  4000aa:   6e                      outsb  %ds:(%rsi),(%dx)
  4000ab:   2f                      (bad)  
  4000ac:   73 68                   jae    400116 <ender+0x74>

I’m going to take guess and say that it is addresses that are marked (bad) which is causing the seg fault. I know this is happening because it wants mem access to mem not allocated to it. I’m not really to sure what I should do. I am running Linux.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:50:48+00:00Added an answer on June 2, 2026 at 4:50 am

    It’s segfaulting because you are attempting to write data to a code (.text) area of memory. Executable code areas are almost always marked as read-only.

    Here’s your code with some additional comments.

    .section .data
    .section .text
    .globl _start
    
    _start:
        xor %rax, %rax
        mov $70, %al
        xor %rbx, %rbx
        xor %rcx, %rcx
        ; call sys_setreuid(0,0)
        int $0x80
    
        jmp ender
    
    starter:
        ; take the return address off the stack
        ; rbx will point to the /bin/sh string after the call instruction
        pop %rbx
        ; zero rax
        xor %rax, %rax
        ; save a zero byte to the end of the /bin/sh string (it's 7 characters long)...
        ; (it will segfault here because you're writing to a read-only area)
        mov %al, 0x07(%rbx)
        ; ...followed by a pointer to the string... 
        mov %rbx, 0x08(%rbx)
        ; ...followed by another zero value 
        mov %rax, 0x0c(%rbx)
        ; setup the parameters for a sys_execve call
        mov $11, %al
        lea 0x08(%rbx), %rcx
        lea 0x0c(%rbx), %rdx
        int $0x80
    
        ; what happens when int 0x80 returns? 
        ; you should do something here or starter will be called again
    
    ender:
        call starter
        .string "/bin/sh"
    

    There are other issues with the code. Consider:

    mov %rbx, 0x08(%rbx)
    mov %rax, 0x0c(%rbx)
    

    %rbx is an 8 byte value, but the code only gives it 4 bytes worth of space (0x0c-0x08 = 4).
    If you want to get it working, you’ll need to move the string into a .data area (with some additional space after it) and change the code to make it 64-bit friendly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.