[gelöst] LKM do_debug hooken

Hi Leute,
Ich will die Rootkit-Technik aus p65 (.:: Phrack Magazine ::.) implementieren, doch wenn ich do_debug hooken will (ich überschreibe den call in ENTRY(debug) mit meinem eigenen do_debug) bekomme ich nur einen kernel oops:
[ 5259.489599] BUG: unable to handle kernel paging request at c05cb608

Die Page ist wohl read-only; wie kann ich sie beschreibbar machen?

grüße CK.

EDIT:
Code:
[ 5259.489599] BUG: unable to handle kernel paging request at c05cb608
[ 5259.489606] IP: [<fee8205c>] get_do_debug+0x4c/0x70 [main2]
[ 5259.489611] *pde = 36882063 *pte = 005cb161 
[ 5259.489615] Oops: 0003 [#1] SMP 
[ 5259.489618] last sysfs file: /sys/devices/pci0000:00/0000:00:1f.2/host2/target2:0:0/2:0:0:0/block/sda/uevent
[ 5259.489621] Modules linked in: main2(P+) nls_utf8 isofs parport_pc ppdev binfmt_misc snd_hda_codec_realtek snd_hda_codec_intelhdmi snd_hda_intel snd_hda_codec snd_hwdep snd_pcm snd_seq_midi i915 snd_rawmidi snd_seq_midi_event snd_seq snd_timer snd_seq_device drm_kms_helper drm snd ndiswrapper intel_agp led_class psmouse serio_raw agpgart i2c_algo_bit video output soundcore snd_page_alloc lp parport r8169 mii [last unloaded: main2]
[ 5259.489649] 
[ 5259.489652] Pid: 5172, comm: insmod Tainted: P            2.6.35-28-generic #50-Ubuntu G41D3+/G41D3+
[ 5259.489655] EIP: 0060:[<fee8205c>] EFLAGS: 00010246 CPU: 1
[ 5259.489658] EIP is at get_do_debug+0x4c/0x70 [main2]
[ 5259.489660] EAX: c05cb607 EBX: 000000a4 ECX: 00000000 EDX: 00000000
[ 5259.489662] ESI: fee820e0 EDI: 00000000 EBP: f1081f4c ESP: f1081f40
[ 5259.489664]  DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068
[ 5259.489667] Process insmod (pid: 5172, ti=f1080000 task=f48932c0 task.ti=f1080000)
[ 5259.489669] Stack:
[ 5259.489671]  0060b5bc c05c8e00 098cf018 f1081f5c fee82090 f1081f78 c016b9c4 f1081f88
[ 5259.489677] <0> c0101132 fee820e0 c07d2f60 098cf018 fee820e0 00004000 fee82080 098cf018
[ 5259.489683] <0> fee820e0 00004000 f1081fac c018109b 00000003 f1081fac c0217345 f27a1840
[ 5259.489689] Call Trace:
[ 5259.489697]  [<c05c8e00>] ? wait_for_common+0x90/0x120
[ 5259.489701]  [<fee82090>] ? init_module+0x10/0x24 [main2]
[ 5259.489705]  [<c016b9c4>] ? __blocking_notifier_call_chain+0x54/0x70
[ 5259.489709]  [<c0101132>] ? do_one_initcall+0x32/0x1a0
[ 5259.489712]  [<fee82080>] ? init_module+0x0/0x24 [main2]
[ 5259.489717]  [<c018109b>] ? sys_init_module+0x9b/0x1e0
[ 5259.489721]  [<c0217345>] ? sys_close+0x75/0xc0
[ 5259.489725]  [<c05caeb4>] ? syscall_call+0x7/0xb
[ 5259.489727] Code: 0f b7 55 f4 89 45 f8 66 31 c0 09 d0 80 38 e8 74 0e 8d b6 00 00 00 00 83 c0 01 80 38 e8 75 f8 0f b6 48 03 0f b6 50 04 0f b6 58 01 <c6> 40 01 ff 0f b6 c9 c1 e1 10 c1 e2 18 09 ca 0f b6 48 02 83 c4 
[ 5259.489762] EIP: [<fee8205c>] get_do_debug+0x4c/0x70 [main2] SS:ESP 0068:f1081f40
[ 5259.489766] CR2: 00000000c05cb608
[ 5259.489769] ---[ end trace 18bb6720abf61c25 ]---
 
Zuletzt bearbeitet:
Hey ho,

Die Page ist wohl read-only; wie kann ich sie beschreibbar machen?

Keine Ahnung mit was du da hantierst, also Sprachtechnisch, aber es sollte möglich sein einfach mal ein "chmod 777" oder "chmod 775" raus zu hauen.

Informier dich doch mal, bei dem was du da machst, nach shell-commands.

Das geht auch in höheren Sprachen wie Java, C++, C# und C sowieso. In Skripten wie Bash macht man eigentlich nie etwas anderes ;)

LG WhiTeY


P.S.: Du brauchst natürlich die nötigen Rechte um die Rechte ändern zu können. Ein Teufelskreis :D
 
Whitey, danke, dass du mir helfen willst, nur es hilft mir kein Stück weiter.

Ich will NICHT die Berechtigungen irgendeiner Datei ändern oder sowas, wenn ich das wollte hättest du recht.
Ich will einen Opcode im kernel-speicher ändern, sowas wie
Code:
(pseudo code)
int main()
{
  // set the first byte of main to 0x90
  *main = 0x90;
}
bloss im kernel speicher.

Verstehst du jetzt was ich will?

/CK
 
mprotect(2) - Linux man page

Ich kenne mich zwar im Linuxkernel nicht wirklich aus, aber auf mich macht die Fehlermeldung nicht den Eindruck, dass es sich um eine Zugriffsverletzung handelt - dann würde ich eher etwas in der Richtung ACCESS_VIOLATION wie bei Windows erwarten.
 
Ich bin mir durchaus über mprotect im Klaren, denke aber nicht, dass es mir weiterhilft, probieren werde ich es aber trotzdem mal :).

ENOMEM
Internal kernel structures could not be allocated. Or: addresses in the range [addr, addr+len] are invalid for the address space of the process, or specify one or more pages that are not mapped.

und ich glaube kaum, dass kmem zum address space des Prozesses gehört....

/CK

PS: ich werde, wenn ich sys_mprotect ausprobiert habe, hier das resultat reineditieren.


Ich habe hier: http://stackoverflow.com/questions/3825018/how-does-mprotect-work noch etwas zu mprotect gefunden:
mprotect() works internally by altering the flags attached to a VMA. The first thing it must do is look up the VMA corresponding to the address that was passed - if the passed address was within the kernel's address range, then there is no VMA, and so this search will fail. This is exactly the same thing happens if you try to change the protections on an area of the address space that is not mapped.
Ich kann mir das ausprobieren also sparen.


EDIT: ICH HAB'S GELÖST :D

Ich setze einfach das READ/WRITE Bit im passenden Page Table Entry und ich kann die Page beschreiben; Für die Interessierten hier die Funktion, mit der ich das bewerkstelligt habe:
Code:
static void write_ro_mem(unsigned char *to, unsigned char *from, unsigned int sz)
{
        int i;
        unsigned long address = (unsigned long)to;
        pgd_t *base = __va(read_cr3());
        pgd_t *pgd = &base[pgd_index(address)];
        pmd_t *pmd;
        pte_t *pte;

        pmd = pmd_offset(pud_offset(pgd, address), address);
        printk(KERN_CONT "*pde = %0*Lx ", sizeof(*pmd) * 2, (u64)pmd_val(*pmd));

        pte = pte_offset_kernel(pmd, address);
        printk("*pte = %0*Lx ", sizeof(*pte) * 2, (u64)pte_val(*pte));


        pte->pte |= _PAGE_RW;


        for (i = 0; i < sz; i++) {
                to[i] = from[i];
        }


        pte->pte &= ~_PAGE_RW;

        printk("\n");
}
 
Zuletzt bearbeitet:
Coole sache und ich versteh so garnix xD

Ich glaub das sind Dinge an die ich mich nie ranführen kann. Hardwarenahes Proggen... Respekt aber nix für mich :D
 
Zurück
Oben