在cpp

时间:2018-01-16 10:26:10

标签: c++ function-pointers shellcode

我正在尝试在cpp中运行shellcode(shellcode来自用户,因此程序应该是动态的) 当我尝试运行我的程序时,我得到了一个异常,我认为它告诉我,我无法从数据部分运行代码。 之后,我尝试创建一个新的可排除部分,并将数据放在那里,但它不起作用

#pragma section(".shell",read,execute)                                                                                                                        
__declspec(allocate(".shell"))
unsigned char code[] =
"\xB8\x04\x00\x00\x00";

// Function pointer points to the address of function.
int(*shell)(); //Function pointer
// Initializing a function pointer  with the address of a shellcode
shell = ((int(*)())&code);
// Execute shellcode
int a = shell();

有人可以向我解释我做错了什么吗?

1 个答案:

答案 0 :(得分:0)

你写的所有内容都是正确的。引发异常只是因为您的shellcode只包含0x00。 Windows分配器将您的部分与页面大小对齐并用零填充,但add byte ptr [rax], almov eax, 4的操作码。现在,您的shellcode中不仅有mov eax, 4 add byte ptr [rax],al add byte ptr [rax],al .... ,还有:

mov

eax之后,您尝试在0x00000004地址0xC0000005: Access violation on write "0x0000000000000004"获取价值,其中放置了Windows页面防护。 现在你有ret

unsigned char code[] = ""\xB8\x04\x00\x00\x00\xC3" 添加到您的shellcode:

    view.addSubview(progressTextVisualEffectView)
    NSLayoutConstraint.activate([
        progressTextVisualEffectView.topAnchor.constraint(equalTo: iosImage.topAnchor, constant: 20),
        progressTextVisualEffectView.leftAnchor.constraint(equalTo: iosImage.leftAnchor, constant: 20),
        progressTextVisualEffectView.heightAnchor.constraint(equalToConstant: 36),
        ])
    progressTextVisualEffectView.autoresizesSubviews = true

    progressTextVisualEffectView.contentView.addSubview(progressLabel)
    NSLayoutConstraint.activate([
        progressLabel.centerXAnchor.constraint(equalTo: progressTextVisualEffectView.centerXAnchor),
        progressLabel.centerYAnchor.constraint(equalTo: progressTextVisualEffectView.centerYAnchor),
        progressLabel.rightAnchor.constraint(equalTo: progressTextVisualEffectView.rightAnchor, constant: -10),
        progressLabel.leftAnchor.constraint(equalTo: progressTextVisualEffectView.leftAnchor, constant: 10)
        ])

}

let progressLabel: UILabel = {
    let label = UILabel()
    label.translatesAutoresizingMaskIntoConstraints = false
    label.text = "1 / 111112"
    label.textColor = UIColor(white: 1, alpha: 0.7)
    label.font = UIFont.systemFont(ofSize: 15, weight: .semibold)
    label.sizeToFit()
    return label
}()

let progressTextVisualEffectView: UIVisualEffectView = {
    let blurEffect = UIBlurEffect(style: .dark)
    let blur = UIVisualEffectView(effect: blurEffect)
    blur.layer.cornerRadius = 12
    blur.clipsToBounds = true
    blur.translatesAutoresizingMaskIntoConstraints = false
    blur.sizeToFit()
    return blur
}()

你不会执行未使用的命令并成功退出。