Técnicas AntiCracking – Parte II – Eliminação de Informação Simbólica

October 18th, 2008 by SAWP | Filed under Programming Internals

“É claro que meus filhos terão computadores, mas antes terão livros.”
[William Henry Gates III]

 

 

Se um desenvolvedor deseja se inteirar de como age um cracker deve testar se seu programa gera informações simbólicas antes de lançá-lo no mercado. Ainda que não seja possível remover toda essa informação da estrutura de um programa, modificar alguns pontos críticos pode ser crucial para o sucesso ou não da proteção.

A eliminação total não ocorre porque programamos em linguagens de alto nível, como C e C++, que são convertidas em instruções processáveis através de um compilador. É o compilador que acaba gerando dados que servem como “pontos de referências” para quem investiga um código disassemblado.

Os compiladores costumam gerar informações simbólicas – para representar as lincagens – quando convertem as relações de importação e exportação de tabelas e extensões. Um programa com grande uso de DLLs, onde cada uma exporta uma grande quantidade de funções, necessitará de uma lista relacionando onde estão as funções exportadas, normalmente indicando o que elas fazem, o que é de grande serventia para os crackers.

Para confundir as referências que possam ser lógicas para o cracker, vale a pena exportar as funções com números ao invés de nomes. Essa pequena medida é eficiente no atraso do trabalho de um cracker, especialmente se usadas linguagens de orientadas a objetos, como C++ e Turbo Pascal.

Pessoalmente, nas poucas vezes que me deparei com códigos numéricos referenciando subrotinas acabei desistindo do trabalho devido à exaustiva e tediosa tarefa de só me ter números com pouco sentido.

A questão da informação simbólica é diferente com as linguagens que geram um assembly em bytecode. Estas linguagens muitas vezes usam códigos nominais internos para a referenciação dos endereços. Então, todos nomes internos são preservados quando o programa é compilado. Por esta estrutura nominal, os bytecodes são mais facilmente decompilados que os códigos binários.

As strings não podem ser simplesmente eliminadas, mas elas podem ser recolocadas com outras strings de forma que as referências cruzadas não fiquem prejudicadas.

Veja o código que mantém as informações simbólicas:

  1.  
  2. #include < stdio .h >
  3.  
  4. #define NMAX 1000
  5. #define APR0 "O CRIVO DE ERASTOTENES\n"
  6. #define APR1 "Codigo com informacao simbolica explicita\n"
  7. #define APR2 "www.sawp.com.br \n\n"
  8.  
  9. int pilhaCrivo[NMAX];
  10.  
  11.  
  12. void apresentacao(){
  13.         printf(APR0);
  14.         printf(APR1);
  15.         printf(APR2);
  16. }
  17.  
  18. void fazListaDeNumeros(){
  19.         int i=0;
  20.         for (i=2; i< =NMAX; i++) {
  21.                 pilhaCrivo[i]=i;
  22.         }
  23. }
  24.  
  25. void mostra(void){
  26.         int i,j;
  27.         for (i=2; i<=NMAX; i++) {
  28.                 if (pilhaCrivo[i]==i) {
  29.                     printf("%d \n", i);
  30.                     for (j=i+i; j<=NMAX; j+=i) {
  31.                         pilhaCrivo[j]=0;
  32.                     }
  33.                 }
  34.             }
  35. }
  36.  
  37. int main() {
  38.         apresentacao();
  39.         fazListaDeNumeros();
  40.         mostra();
  41.  
  42.         return 1;
  43. }
  44.  

Agora veja o código abaixo, onde as informações simbólicas foram removidas:

  1.  
  2. #include < 8203099666.h >
  3. #include < 1010011010.h >
  4. #include < 75981212.h >
  5. using std::string;
  6. using std::cout;
  7.  
  8. #define N32MMX2 1000
  9. #define APR1 "Htinlt%htr%nsktwrfhft%xnrgtqnhf%j}uqnhnyf3"
  10. #define APR2 "|||3xf|u3htr3gw"
  11. #define APR0
  12. T%HWN[T%IJ%JWFXYTYJSJX
  13.  
  14.  
  15. int PH040x12[N32MMX2];
  16.  
  17.  
  18. void rot13_d3c0d3(string & INx990012){
  19.         const int kkk=5;
  20.         int a5c11c0d3;
  21.  
  22.         for(int i=0;i< inx990012 .length();i++) {
  23.                 a5c11c0d3 = static_cast< int >(INx990012[i])- kkk;
  24.                 INx990012[i] =  static_cast< char >(a5c11c0d3);
  25.         }
  26. }
  27.  
  28. void st4rt3R_09833(){
  29.         string h0xx3232122[] = {APR0, APR1, APR2};
  30.  
  31.         rot13_d3c0d3(h0xx3232122[0]);
  32.         rot13_d3c0d3(h0xx3232122[1]);
  33.         rot13_d3c0d3(h0xx3232122[2]);
  34.  
  35.         cout < < h0xx3232122[0] < < "\n" < < h0xx3232122[1] < < "\n" < < h0xx3232122[2] < < "\n\n";
  36. }
  37.  
  38.  
  39. void HP00x98765432(){
  40.         int i=0;
  41.         for (i=2; i <= N32MMX2; i++) {
  42.                 PH040x12[i]=i;
  43.         }
  44. }
  45.  
  46. void IB00x98701234(void){
  47.         int i,j;
  48.         for (i=2; i <= N32MMX2; i++) {
  49.                 if (PH040x12[i]==i) {
  50.                     printf("%d \n", i);
  51.                     for (j=i+i; j <= N32MMX2; j+=i) {
  52.                         PH040x12[j]=0;
  53.                     }
  54.                 }
  55.             }
  56. }
  57.  
  58. int main() {
  59.         st4rt3R_09833();
  60.         HP00x98765432();
  61.         IB00x98701234();
  62.  
  63.         return 1;
  64. }
  65.  

Da mesma forma, comparemos o código em assembly:

  1.  
  2.         .file   "main.c"
  3.         .section .rdata,"dr"
  4. LC0:
  5.         .ascii "O CRIVO DE ERASTOTENES\12\0"
  6.         .align 4
  7. LC1:
  8.         .ascii "Codigo com informacao simbolica explicita\12\0"
  9. LC2:
  10.         .ascii "www.sawp.com.br \12\12\0"
  11.         .text
  12. .globl _apresentacao
  13.         .def    _apresentacao;  .scl    2;      .type   32;     .endef
  14. _apresentacao:
  15.         pushl   %ebp
  16.         movl    %esp, %ebp
  17.         subl    $8, %esp
  18.         movl    $LC0, (%esp)
  19.         call    _printf
  20.         movl    $LC1, (%esp)
  21.         call    _printf
  22.         movl    $LC2, (%esp)
  23.         call    _printf
  24.         leave
  25.         ret
  26. .globl _fazListaDeNumeros
  27.         .def    _fazListaDeNumeros;     .scl    2;      .type   32;     .endef
  28. _fazListaDeNumeros:
  29.         pushl   %ebp
  30.         movl    %esp, %ebp
  31.         subl    $4, %esp
  32.         movl    $0, -4(%ebp)
  33.         movl    $2, -4(%ebp)
  34. L3:
  35.         cmpl    $1000, -4(%ebp)
  36.         jg      L2
  37.         movl    -4(%ebp), %edx
  38.         movl    -4(%ebp), %eax
  39.         movl    %eax, _pilhaCrivo(,%edx,4)
  40.         leal    -4(%ebp), %eax
  41.         incl    (%eax)
  42.         jmp     L3
  43. L2:
  44.         leave
  45.         ret
  46.         .section .rdata,"dr"
  47. LC3:
  48.         .ascii "%d \12\0"
  49.         .text
  50. .globl _mostra
  51.         .def    _mostra;        .scl    2;      .type   32;     .endef
  52. _mostra:
  53.         pushl   %ebp
  54.         movl    %esp, %ebp
  55.         subl    $24, %esp
  56.         movl    $2, -4(%ebp)
  57. L7:
  58.         cmpl    $1000, -4(%ebp)
  59.         jg      L6
  60.         movl    -4(%ebp), %eax
  61.         movl    _pilhaCrivo(,%eax,4), %eax
  62.         cmpl    -4(%ebp), %eax
  63.         jne     L9
  64.         movl    -4(%ebp), %eax
  65.         movl    %eax, 4(%esp)
  66.         movl    $LC3, (%esp)
  67.         call    _printf
  68.         movl    -4(%ebp), %eax
  69.         addl    -4(%ebp), %eax
  70.         movl    %eax, -8(%ebp)
  71. L11:
  72.         cmpl    $1000, -8(%ebp)
  73.         jg      L9
  74.         movl    -8(%ebp), %eax
  75.         movl    $0, _pilhaCrivo(,%eax,4)
  76.         movl    -4(%ebp), %edx
  77.         leal    -8(%ebp), %eax
  78.         addl    %edx, (%eax)
  79.         jmp     L11
  80. L9:
  81.         leal    -4(%ebp), %eax
  82.         incl    (%eax)
  83.         jmp     L7
  84. L6:
  85.         leave
  86.         ret
  87.         .def    ___main;        .scl    2;      .type   32;     .endef
  88. .globl _main
  89.         .def    _main;  .scl    2;      .type   32;     .endef
  90. _main:
  91.         pushl   %ebp
  92.         movl    %esp, %ebp
  93.         subl    $8, %esp
  94.         andl    $-16, %esp
  95.         movl    $0, %eax
  96.         addl    $15, %eax
  97.         addl    $15, %eax
  98.         shrl    $4, %eax
  99.         sall    $4, %eax
  100.         movl    %eax, -4(%ebp)
  101.         movl    -4(%ebp), %eax
  102.         call    __alloca
  103.         call    ___main
  104.         call    _apresentacao
  105.         call    _fazListaDeNumeros
  106.         call    _mostra
  107.         movl    $1, %eax
  108.         leave
  109.         ret
  110.         .comm   _pilhaCrivo, 4000        # 4000
  111.         .def    _printf;        .scl    2;      .type   32;     .endef
  112.  

Agora o mesmo código sem informações simbólicas explícitas:

  1.  
  2.         .file   "main.cpp"
  3.         .text
  4.         .align 2
  5.         .def    __ZSt17__verify_groupingPKcjRKSs;       .scl    3;      .type   32;     .endef
  6. __ZSt17__verify_groupingPKcjRKSs:
  7.         pushl   %ebp
  8.         movl    %esp, %ebp
  9.         subl    $40, %esp
  10.         movl    16(%ebp), %eax
  11.         movl    %eax, (%esp)
  12.         call    __ZNKSs4sizeEv
  13.         decl    %eax
  14.         movl    %eax, -4(%ebp)
  15.         movl    12(%ebp), %eax
  16.         decl    %eax
  17.         movl    %eax, -12(%ebp)
  18.         leal    -12(%ebp), %eax
  19.         movl    %eax, 4(%esp)
  20.         leal    -4(%ebp), %eax
  21.         movl    %eax, (%esp)
  22.         call    __ZSt3minIjERKT_S2_S2_
  23.         movl    (%eax), %eax
  24.         movl    %eax, -8(%ebp)
  25.         movl    -4(%ebp), %eax
  26.         movl    %eax, -16(%ebp)
  27.         movb    $1, -17(%ebp)
  28.         movl    $0, -24(%ebp)
  29. L2:
  30.         movl    -24(%ebp), %eax
  31.         cmpl    -8(%ebp), %eax
  32.         jae     L5
  33.         cmpb    $0, -17(%ebp)
  34.         je      L5
  35.         movl    -16(%ebp), %eax
  36.         movl    %eax, 4(%esp)
  37.         movl    16(%ebp), %eax
  38.         movl    %eax, (%esp)
  39.         call    __ZNKSsixEj
  40.         movsbl  (%eax),%edx
  41.         movl    8(%ebp), %eax
  42.         addl    -24(%ebp), %eax
  43.         movsbl  (%eax),%eax
  44.         cmpl    %eax, %edx
  45.         sete    %al
  46.         movb    %al, -17(%ebp)
  47.         leal    -16(%ebp), %eax
  48.         decl    (%eax)
  49.         leal    -24(%ebp), %eax
  50.         incl    (%eax)
  51.         jmp     L2
  52. L5:
  53.         cmpl    $0, -16(%ebp)
  54.         je      L6
  55.         cmpb    $0, -17(%ebp)
  56.         je      L6
  57.         movl    -16(%ebp), %eax
  58.         movl    %eax, 4(%esp)
  59.         movl    16(%ebp), %eax
  60.         movl    %eax, (%esp)
  61.         call    __ZNKSsixEj
  62.         movsbl  (%eax),%edx
  63.         movl    8(%ebp), %eax
  64.         addl    -8(%ebp), %eax
  65.         movsbl  (%eax),%eax
  66.         cmpl    %eax, %edx
  67.         sete    %al
  68.         movb    %al, -17(%ebp)
  69.         leal    -16(%ebp), %eax
  70.         decl    (%eax)
  71.         jmp     L5
  72. L6:
  73.         movl    $0, 4(%esp)
  74.         movl    16(%ebp), %eax
  75.         movl    %eax, (%esp)
  76.         call    __ZNKSsixEj
  77.         movsbl  (%eax),%edx
  78.         movl    8(%ebp), %eax
  79.         addl    -8(%ebp), %eax
  80.         movsbl  (%eax),%eax
  81.         cmpl    %eax, %edx
  82.         jg      L8
  83.         movzbl  -17(%ebp), %eax
  84.         andl    $1, %eax
  85.         movb    %al, -25(%ebp)
  86.         jmp     L9
  87. L8:
  88.         movb    $0, -25(%ebp)
  89. L9:
  90.         movzbl  -25(%ebp), %eax
  91.         movb    %al, -17(%ebp)
  92.         movzbl  -17(%ebp), %eax
  93.         leave
  94.         ret
  95. .lcomm __ZSt8__ioinit,16
  96. .globl _PH040x12
  97.         .bss
  98.         .align 32
  99. _PH040x12:
  100.         .space 4000
  101.         .text
  102.         .align 2
  103. .globl __Z12rot13_d3c0d3RSs
  104.         .def    __Z12rot13_d3c0d3RSs;   .scl    2;      .type   32;     .endef
  105. __Z12rot13_d3c0d3RSs:
  106.         pushl   %ebp
  107.         movl    %esp, %ebp
  108.         subl    $24, %esp
  109.         movl    $5, -4(%ebp)
  110.         movl    $0, -12(%ebp)
  111. L11:
  112.         movl    8(%ebp), %eax
  113.         movl    %eax, (%esp)
  114.         call    __ZNKSs6lengthEv
  115.         cmpl    %eax, -12(%ebp)
  116.         jae     L10
  117.         movl    -12(%ebp), %eax
  118.         movl    %eax, 4(%esp)
  119.         movl    8(%ebp), %eax
  120.         movl    %eax, (%esp)
  121.         call    __ZNSsixEj
  122.         movsbl  (%eax),%eax
  123.         subl    $5, %eax
  124.         movl    %eax, -8(%ebp)
  125.         movl    -12(%ebp), %eax
  126.         movl    %eax, 4(%esp)
  127.         movl    8(%ebp), %eax
  128.         movl    %eax, (%esp)
  129.         call    __ZNSsixEj
  130.         movl    %eax, %edx
  131.         movl    -8(%ebp), %eax
  132.         movb    %al, (%edx)
  133.         leal    -12(%ebp), %eax
  134.         incl    (%eax)
  135.         jmp     L11
  136. L10:
  137.         leave
  138.         ret
  139.         .def    __Unwind_SjLj_Resume;   .scl    2;      .type   32;     .endef
  140.         .def    ___gxx_personality_sj0; .scl    2;      .type   32;     .endef
  141.         .def    __Unwind_SjLj_Register; .scl    2;      .type   32;     .endef
  142.         .def    __Unwind_SjLj_Unregister;       .scl    2;      .type   32;     .endef
  143.         .section .rdata,"dr"
  144. LC0:
  145.         .ascii "T%HWN[T%IJ%JWFXYTYJSJX\0"
  146.         .align 4
  147. LC1:
  148.         .ascii "Htinlt%htr%nsktwrfhft%xnrgtqnhf%j}uqnhnyf3\0"
  149. LC2:
  150.         .ascii "|||3xf|u3htr3gw\0"
  151. LC3:
  152.         .ascii "\12\0"
  153. LC4:
  154.         .ascii "\12\12\0"
  155.         .text
  156.         .align 2
  157. .globl __Z13st4rt3R_09833v
  158.         .def    __Z13st4rt3R_09833v;    .scl    2;      .type   32;     .endef
  159. __Z13st4rt3R_09833v:
  160.         pushl   %ebp
  161.         movl    %esp, %ebp
  162.         pushl   %edi
  163.         pushl   %esi
  164.         pushl   %ebx
  165.         subl    $172, %esp
  166.         movl    $___gxx_personality_sj0, -84(%ebp)
  167.         movl    $LLSDA1426, -80(%ebp)
  168.         leal    -76(%ebp), %eax
  169.         leal    -24(%ebp), %edx
  170.         movl    %edx, (%eax)
  171.         movl    $L47, %edx
  172.         movl    %edx, 4(%eax)
  173.         movl    %esp, 8(%eax)
  174.         leal    -108(%ebp), %eax
  175.         movl    %eax, (%esp)
  176.         call    __Unwind_SjLj_Register
  177.         leal    -40(%ebp), %eax
  178.         movl    %eax, -112(%ebp)
  179.         movl    -112(%ebp), %edx
  180.         movl    %edx, -116(%ebp)
  181.         movl    $2, -120(%ebp)
  182.         leal    -56(%ebp), %eax
  183.         movl    %eax, (%esp)
  184.         call    __ZNSaIcEC1Ev
  185.         leal    -56(%ebp), %eax
  186.         movl    %eax, 8(%esp)
  187.         movl    $LC0, 4(%esp)
  188.         movl    -116(%ebp), %eax
  189.         movl    %eax, (%esp)
  190.         movl    $4, -104(%ebp)
  191.         call    __ZNSsC1EPKcRKSaIcE
  192.         jmp     L16
  193. L15:
  194.         movl    -128(%ebp), %edx
  195.         movl    %edx, -124(%ebp)
  196.         leal    -56(%ebp), %eax
  197.         movl    %eax, (%esp)
  198.         call    __ZNSaIcED1Ev
  199.         movl    -124(%ebp), %eax
  200.         movl    %eax, -128(%ebp)
  201. L17:
  202.         jmp     L27
  203. L16:
  204.         leal    -56(%ebp), %eax
  205.         movl    %eax, (%esp)
  206.         call    __ZNSaIcED1Ev
  207.         addl    $4, -116(%ebp)
  208.         decl    -120(%ebp)
  209.         leal    -56(%ebp), %eax
  210.         movl    %eax, (%esp)
  211.         call    __ZNSaIcEC1Ev
  212.         leal    -56(%ebp), %eax
  213.         movl    %eax, 8(%esp)
  214.         movl    $LC1, 4(%esp)
  215.         movl    -116(%ebp), %edx
  216.         movl    %edx, (%esp)
  217.         movl    $3, -104(%ebp)
  218.         call    __ZNSsC1EPKcRKSaIcE
  219.         jmp     L20
  220. L19:
  221.         movl    -128(%ebp), %eax
  222.         movl    %eax, -132(%ebp)
  223.         leal    -56(%ebp), %eax
  224.         movl    %eax, (%esp)
  225.         call    __ZNSaIcED1Ev
  226.         movl    -132(%ebp), %edx
  227.         movl    %edx, -128(%ebp)
  228. L21:
  229.         jmp     L27
  230. L20:
  231.         leal    -56(%ebp), %eax
  232.         movl    %eax, (%esp)
  233.         call    __ZNSaIcED1Ev
  234.         addl    $4, -116(%ebp)
  235.         decl    -120(%ebp)
  236.         leal    -56(%ebp), %eax
  237.         movl    %eax, (%esp)
  238.         call    __ZNSaIcEC1Ev
  239.         leal    -56(%ebp), %eax
  240.         movl    %eax, 8(%esp)
  241.         movl    $LC2, 4(%esp)
  242.         movl    -116(%ebp), %eax
  243.         movl    %eax, (%esp)
  244.         movl    $2, -104(%ebp)
  245.         call    __ZNSsC1EPKcRKSaIcE
  246.         jmp     L24
  247. L23:
  248.         movl    -128(%ebp), %edx
  249.         movl    %edx, -136(%ebp)
  250.         leal    -56(%ebp), %eax
  251.         movl    %eax, (%esp)
  252.         call    __ZNSaIcED1Ev
  253.         movl    -136(%ebp), %eax
  254.         movl    %eax, -128(%ebp)
  255. L25:
  256.         jmp     L27
  257. L24:
  258.         leal    -56(%ebp), %eax
  259.         movl    %eax, (%esp)
  260.         call    __ZNSaIcED1Ev
  261.         decl    -120(%ebp)
  262.         jmp     L28
  263. L27:
  264.         movl    -128(%ebp), %edx
  265.         movl    %edx, -140(%ebp)
  266.         cmpl    $0, -112(%ebp)
  267.         je      L30
  268.         movl    $2, %eax
  269.         subl    -120(%ebp), %eax
  270.         movl    %eax, -144(%ebp)
  271.         movl    -144(%ebp), %eax
  272.         sall    $2, %eax
  273.         movl    -112(%ebp), %edx
  274.         addl    %eax, %edx
  275.         movl    %edx, -144(%ebp)
  276. L31:
  277.         movl    -144(%ebp), %eax
  278.         cmpl    %eax, -112(%ebp)
  279.         je      L30
  280.         subl    $4, -144(%ebp)
  281.         movl    -144(%ebp), %edx
  282.         movl    %edx, (%esp)
  283.         movl    $0, -104(%ebp)
  284.         call    __ZNSsD1Ev
  285.         jmp     L31
  286. L30:
  287.         movl    -140(%ebp), %eax
  288.         movl    %eax, -128(%ebp)
  289. L33:
  290.         movl    -128(%ebp), %edx
  291.         movl    %edx, (%esp)
  292.         movl    $-1, -104(%ebp)
  293.         call    __Unwind_SjLj_Resume
  294. L28:
  295.         leal    -40(%ebp), %eax
  296.         movl    %eax, (%esp)
  297.         movl    $1, -104(%ebp)
  298.         call    __Z12rot13_d3c0d3RSs
  299.         leal    -40(%ebp), %eax
  300.         addl    $4, %eax
  301.         movl    %eax, (%esp)
  302.         call    __Z12rot13_d3c0d3RSs
  303.         leal    -40(%ebp), %eax
  304.         addl    $8, %eax
  305.         movl    %eax, (%esp)
  306.         call    __Z12rot13_d3c0d3RSs
  307.         leal    -40(%ebp), %eax
  308.         movl    %eax, 4(%esp)
  309.         movl    $__ZSt4cout, (%esp)
  310.         call    __ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKSbIS4_S5_T1_E
  311.         movl    $LC3, 4(%esp)
  312.         movl    %eax, (%esp)
  313.         call    __ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
  314.         leal    -40(%ebp), %edx
  315.         addl    $4, %edx
  316.         movl    %edx, 4(%esp)
  317.         movl    %eax, (%esp)
  318.         call    __ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKSbIS4_S5_T1_E
  319.         movl    $LC3, 4(%esp)
  320.         movl    %eax, (%esp)
  321.         call    __ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
  322.         leal    -40(%ebp), %edx
  323.         addl    $8, %edx
  324.         movl    %edx, 4(%esp)
  325.         movl    %eax, (%esp)
  326.         call    __ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKSbIS4_S5_T1_E
  327.         movl    $LC4, 4(%esp)
  328.         movl    %eax, (%esp)
  329.         call    __ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
  330.         jmp     L36
  331. L47:
  332.         leal    24(%ebp), %ebp
  333.         movl    -104(%ebp), %eax
  334.         movl    %eax, -156(%ebp)
  335.         movl    -100(%ebp), %edx
  336.         movl    %edx, -128(%ebp)
  337.         cmpl    $1, -156(%ebp)
  338.         je      L23
  339.         cmpl    $2, -156(%ebp)
  340.         je      L19
  341.         cmpl    $3, -156(%ebp)
  342.         je      L15
  343. L35:
  344.         movl    -128(%ebp), %eax
  345.         movl    %eax, -148(%ebp)
  346.         leal    -40(%ebp), %eax
  347.         testl   %eax, %eax
  348.         je      L38
  349.         leal    -40(%ebp), %edx
  350.         movl    %edx, -152(%ebp)
  351.         addl    $12, -152(%ebp)
  352. L39:
  353.         leal    -40(%ebp), %eax
  354.         cmpl    -152(%ebp), %eax
  355.         je      L38
  356.         subl    $4, -152(%ebp)
  357.         movl    -152(%ebp), %eax
  358.         movl    %eax, (%esp)
  359.         movl    $0, -104(%ebp)
  360.         call    __ZNSsD1Ev
  361.         jmp     L39
  362. L38:
  363.         movl    -148(%ebp), %edx
  364.         movl    %edx, -128(%ebp)
  365. L41:
  366.         movl    -128(%ebp), %eax
  367.         movl    %eax, (%esp)
  368.         movl    $-1, -104(%ebp)
  369.         call    __Unwind_SjLj_Resume
  370. L36:
  371.         leal    -40(%ebp), %eax
  372.         testl   %eax, %eax
  373.         je      L14
  374.         leal    -40(%ebp), %edx
  375.         movl    %edx, -152(%ebp)
  376.         addl    $12, -152(%ebp)
  377. L45:
  378.         leal    -40(%ebp), %eax
  379.         cmpl    -152(%ebp), %eax
  380.         je      L14
  381.         subl    $4, -152(%ebp)
  382.         movl    -152(%ebp), %eax
  383.         movl    %eax, (%esp)
  384.         movl    $-1, -104(%ebp)
  385.         call    __ZNSsD1Ev
  386.         jmp     L45
  387. L14:
  388.         leal    -108(%ebp), %eax
  389.         movl    %eax, (%esp)
  390.         call    __Unwind_SjLj_Unregister
  391.         addl    $172, %esp
  392.         popl    %ebx
  393.         popl    %esi
  394.         popl    %edi
  395.         popl    %ebp
  396.         ret
  397.         .section        .gcc_except_table,"dr"
  398. LLSDA1426:
  399.         .byte   0xff
  400.         .byte   0xff
  401.         .byte   0x1
  402.         .uleb128 LLSDACSE1426-LLSDACSB1426
  403. LLSDACSB1426:
  404.         .uleb128 0x0
  405.         .uleb128 0x0
  406.         .uleb128 0x1
  407.         .uleb128 0x0
  408.         .uleb128 0x2
  409.         .uleb128 0x0
  410.         .uleb128 0x3
  411.         .uleb128 0x0
  412. LLSDACSE1426:
  413.         .text
  414.         .align 2
  415. .globl __Z13HP00x98765432v
  416.         .def    __Z13HP00x98765432v;    .scl    2;      .type   32;     .endef
  417. __Z13HP00x98765432v:
  418.         pushl   %ebp
  419.         movl    %esp, %ebp
  420.         subl    $4, %esp
  421.         movl    $0, -4(%ebp)
  422.         movl    $2, -4(%ebp)
  423. L49:
  424.         cmpl    $1000, -4(%ebp)
  425.         jg      L48
  426.         movl    -4(%ebp), %edx
  427.         movl    -4(%ebp), %eax
  428.         movl    %eax, _PH040x12(,%edx,4)
  429.         leal    -4(%ebp), %eax
  430.         incl    (%eax)
  431.         jmp     L49
  432. L48:
  433.         leave
  434.         ret
  435.         .section .rdata,"dr"
  436. LC5:
  437.         .ascii "%d \12\0"
  438.         .text
  439.         .align 2
  440. .globl __Z13IB00x98701234v
  441.         .def    __Z13IB00x98701234v;    .scl    2;      .type   32;     .endef
  442. __Z13IB00x98701234v:
  443.         pushl   %ebp
  444.         movl    %esp, %ebp
  445.         subl    $24, %esp
  446.         movl    $2, -4(%ebp)
  447. L53:
  448.         cmpl    $1000, -4(%ebp)
  449.         jg      L52
  450.         movl    -4(%ebp), %eax
  451.         movl    _PH040x12(,%eax,4), %eax
  452.         cmpl    -4(%ebp), %eax
  453.         jne     L55
  454.         movl    -4(%ebp), %eax
  455.         movl    %eax, 4(%esp)
  456.         movl    $LC5, (%esp)
  457.         call    _printf
  458.         movl    -4(%ebp), %eax
  459.         addl    -4(%ebp), %eax
  460.         movl    %eax, -8(%ebp)
  461. L57:
  462.         cmpl    $1000, -8(%ebp)
  463.         jg      L55
  464.         movl    -8(%ebp), %eax
  465.         movl    $0, _PH040x12(,%eax,4)
  466.         movl    -4(%ebp), %edx
  467.         leal    -8(%ebp), %eax
  468.         addl    %edx, (%eax)
  469.         jmp     L57
  470. L55:
  471.         leal    -4(%ebp), %eax
  472.         incl    (%eax)
  473.         jmp     L53
  474. L52:
  475.         leave
  476.         ret
  477.         .def    ___main;        .scl    2;      .type   32;     .endef
  478.         .align 2
  479. .globl _main
  480.         .def    _main;  .scl    2;      .type   32;     .endef
  481. _main:
  482.         pushl   %ebp
  483.         movl    %esp, %ebp
  484.         subl    $8, %esp
  485.         andl    $-16, %esp
  486.         movl    $0, %eax
  487.         addl    $15, %eax
  488.         addl    $15, %eax
  489.         shrl    $4, %eax
  490.         sall    $4, %eax
  491.         movl    %eax, -4(%ebp)
  492.         movl    -4(%ebp), %eax
  493.         call    __alloca
  494.         call    ___main
  495.         call    __Z13st4rt3R_09833v
  496.         call    __Z13HP00x98765432v
  497.         call    __Z13IB00x98701234v
  498.         movl    $1, %eax
  499.         leave
  500.         ret
  501.         .section        .text$_ZSt3minIjERKT_S2_S2_,"x"
  502.         .linkonce discard
  503.         .align 2
  504. .globl __ZSt3minIjERKT_S2_S2_
  505.         .def    __ZSt3minIjERKT_S2_S2_; .scl    2;      .type   32;     .endef
  506. __ZSt3minIjERKT_S2_S2_:
  507.         pushl   %ebp
  508.         movl    %esp, %ebp
  509.         subl    $4, %esp
  510.         movl    12(%ebp), %eax
  511.         movl    8(%ebp), %edx
  512.         movl    (%eax), %eax
  513.         cmpl    (%edx), %eax
  514.         jae     L62
  515.         movl    12(%ebp), %eax
  516.         movl    %eax, -4(%ebp)
  517.         jmp     L61
  518. L62:
  519.         movl    8(%ebp), %eax
  520.         movl    %eax, -4(%ebp)
  521. L61:
  522.         movl    -4(%ebp), %eax
  523.         leave
  524.         ret
  525.         .text
  526.         .align 2
  527.         .def    __Z41__static_initialization_and_destruction_0ii;       .scl    3;      .type   32;     .endef
  528. __Z41__static_initialization_and_destruction_0ii:
  529.         pushl   %ebp
  530.         movl    %esp, %ebp
  531.         subl    $8, %esp
  532.         cmpl    $65535, 12(%ebp)
  533.         jne     L64
  534.         cmpl    $1, 8(%ebp)
  535.         jne     L64
  536.         movl    $__ZSt8__ioinit, (%esp)
  537.         call    __ZNSt8ios_base4InitC1Ev
  538. L64:
  539.         cmpl    $65535, 12(%ebp)
  540.         jne     L63
  541.         cmpl    $0, 8(%ebp)
  542.         jne     L63
  543.         movl    $__ZSt8__ioinit, (%esp)
  544.         call    __ZNSt8ios_base4InitD1Ev
  545. L63:
  546.         leave
  547.         ret
  548.         .align 2
  549.         .def    __GLOBAL__I_PH040x12;   .scl    3;      .type   32;     .endef
  550. __GLOBAL__I_PH040x12:
  551.         pushl   %ebp
  552.         movl    %esp, %ebp
  553.         subl    $8, %esp
  554.         movl    $65535, 4(%esp)
  555.         movl    $1, (%esp)
  556.         call    __Z41__static_initialization_and_destruction_0ii
  557.         leave
  558.         ret
  559.         .section        .ctors,"w"
  560.         .align 4
  561.         .long   __GLOBAL__I_PH040x12
  562.         .text
  563.         .align 2
  564.         .def    __GLOBAL__D_PH040x12;   .scl    3;      .type   32;     .endef
  565. __GLOBAL__D_PH040x12:
  566.         pushl   %ebp
  567.         movl    %esp, %ebp
  568.         subl    $8, %esp
  569.         movl    $65535, 4(%esp)
  570.         movl    $0, (%esp)
  571.         call    __Z41__static_initialization_and_destruction_0ii
  572.         leave
  573.         ret
  574.         .section        .dtors,"w"
  575.         .align 4
  576.         .long   __GLOBAL__D_PH040x12
  577.         .def    __ZNSt8ios_base4InitD1Ev;       .scl    2;      .type   32;     .endef
  578.         .def    _printf;        .scl    2;      .type   32;     .endef
  579.         .def    __ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc;       .scl    2;      .type   32;     .endef
  580.         .def    __ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKSbIS4_S5_T1_E;   .scl    2;      .type   32;     .endef
  581.         .def    __ZNSsD1Ev;     .scl    2;      .type   32;     .endef
  582.         .def    __ZNSsC1EPKcRKSaIcE;    .scl    2;      .type   32;     .endef
  583.         .def    __ZNSaIcED1Ev;  .scl    2;      .type   32;     .endef
  584.         .def    __ZNSaIcEC1Ev;  .scl    2;      .type   32;     .endef
  585.         .def    __ZNSsixEj;     .scl    2;      .type   32;     .endef
  586.         .def    __ZNKSs6lengthEv;       .scl    2;      .type   32;     .endef
  587.         .def    __ZNSt8ios_base4InitC1Ev;       .scl    2;      .type   32;     .endef
  588.         .def    __ZNKSsixEj;    .scl    2;      .type   32;     .endef
  589.         .def    __ZNKSs4sizeEv; .scl    2;      .type   32;     .endef
  590.  

Ambos códigos realizam a mesma tarefa: exibir a mensagem "O CRIVO DE ERASTOTENES. Codigo com informacao simbolica explicita. www.sawp.com.br” e em seguida-se calcula os números primos existentes de 2 à 1000.

Contudo, claramente observamos no segundo código que as strings não visíveis. Isso faz com que seja quase impossível para o cracker saber sobre o que se trata aquela informação, pois ele precisaria do código responsável pela decriptação da informação simbólica. No caso, a função responsável por tornar o texto visível para o usuário e invisível para o cracker é a “rot13_d3c0d3”.

Para quem tiver curiosidade, rot13_d3c0d3 substitui um caractere por outro que têm seu asccii-13. Veja:

  1.  
  2. void rot13ASC_decode(string & input){
  3.         const int key=13;
  4.         int asciicode;
  5.  
  6.         for(int i=0;i < input .length();i++) {
  7.                 asciicode = static_cast< int >(input[i])- key;
  8.                 input[i] =  static_cast< char >(asciicode);
  9.         }
  10. }
  11.  

Normalmente os crackers se deparam com codificações reversíveis, como BASE64, rot13,rot64, algum algoritmo derivado de Cifras de César-Vigenere ou algum algoritmo de transposição.

Notamos então que colocar as constantes em texto explícito é uma forma extremamente vulnerável por deixar pontos de referências para os crackers se localizarem na nossa aplicação.

Observamos também que o código assembly com as informações simbólicas removidas é muito mais extenso e possui muito mais instruções que o código original. Isso reforça uma das desvantagens descritas na PARTE 1 sobre anti-cracking: sempre há perda de desempenho ao implementar técnicas anticracking.

Este é um ponto importante e que deve sempre estar na cabeça do desenvolvedor. No nosso pequeno exemplo já tivemos um considerável aumento de instruções. E este crescimento é propagado quão maior for o código da aplicação, representando significativa perda de eficiência.

Deve-se ficar claro que o código aqui apresentado é apenas para exemplificar. Alguém que necessite proteger sua aplicação, certamente está trabalhando em um projeto grande, com vários arquivos-fontes, muitas classes e funções. Então, obviamente, não há como eliminar as informações simbólicas “na mão”.

O que as empresas que empregam técnicas anti-cracking fazem é construir parsers especiais e scripts especiais de compilação. Desta forma, o código ao invés de ser enviado direto para o compilador, são transformados por estes scripts em um código de sem informações simbólicas destes e só então são compilados.

Tags: tag_icon [ Programming Internals ]

Você pode ler as eventuais respostas desta entrada através do RSS 2.0 feed.
Você pode deixar uma resposta , ou trackback a partir do seu próprio site.