破解php-screw加密过的文件有效方法

今天终于搞定更改过密钥的php-screw解密问题,乐呵一下!

改进下

这样就可以解密任何加密过的PHP源码(包括更改过密钥的),解密的原理稍后具体列出,先说下如何加密

列出之前写使用php screw加密PHP的自动加密代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "php_screw.h"
#include "my_screw.h"
 
main(int argc, char**argv)
{
    FILE    *fp;
    struct  stat    stat_buf;
    char    *datap, *newdatap;
    int datalen, newdatalen;
    int cryptkey_len = sizeof pm9screw_mycryptkey / 2;
    char    newfilename[256];
    int i;
 
    if (argc != 2) {
        fprintf(stderr, "Usage: filename. ");
        exit(0);
    }
 
    fp = fopen(argv[1], "r");
    if (fp == NULL) {
        fprintf(stderr, "File not found(%s) ", argv[1]);
        exit(0);
    }
 
    fstat(fileno(fp), &stat_buf);
    datalen = stat_buf.st_size;
    datap = (char*)malloc(datalen + PM9SCREW_LEN);
    fread(datap, datalen, 1, fp);
    fclose(fp);
 
    if (memcmp(datap, PM9SCREW, PM9SCREW_LEN) == 0) {
        fprintf(stderr, "Already Crypted(%s) ", argv[1]);
        exit(0);
    }
 
    sprintf(newfilename, "%s.screw", argv[1]);
 
    fp = fopen(newfilename, "w");
    if (fp == NULL) {
        fprintf(stderr, "Can not create file(%s) ", newfilename);
        exit(0);
    }
 
    newdatap = zencode(datap, datalen, &newdatalen);
 
    for(i=0; i<newdatalen; i++) {
        newdatap[i] = (char)pm9screw_mycryptkey[(newdatalen - i) % cryptkey_len] ^ (~(newdatap[i]));
    }
 
    fwrite(PM9SCREW, PM9SCREW_LEN, 1, fp);
    fwrite(newdatap, newdatalen, 1, fp);
    fclose(fp);
    fprintf(stderr, "Success Crypting(%s) ", argv[1]);
    free(newdatap);
    free(datap);
}
原文地址:https://www.cnblogs.com/wangluochong/p/4890850.html