美文网首页
0CTF 2015 Quals CTF VEZEL Writeu

0CTF 2015 Quals CTF VEZEL Writeu

作者: hyrathon | 来源:发表于2017-09-30 17:01 被阅读0次

Category: Mobile
Points: 100
Solves: 105
Description:

Evermars says he is good at repackaging Android applications, for example.

Write-up

分析过程可以参考下面三个链接, 程序很简单flag由两个字符串相加内容计算, 其中一个getCRC可以直接得到, 而apk签名可以用Main.class运行得到, 比较笨的办法是自己写一个apk, 利用PackageManager得到签名.

Other write-ups and resources

import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.security.Signature;
import java.security.cert.*;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
 
public class Main {
 
 private static final Object mSync = new Object();
 private static WeakReference<byte[]> mReadBuffer;
 
 public static void main(String[] args) {
  if (args.length < 1) {
   System.out.println("Usage: java -jar GetAndroidSig.jar <apk/jar>");
   System.exit(-1);
  }
 
  System.out.println(args[0]);
 
  String mArchiveSourcePath = args[0];
 
  WeakReference<byte[]> readBufferRef;
  byte[] readBuffer = null;
  synchronized (mSync) {
   readBufferRef = mReadBuffer;
   if (readBufferRef != null) {
    mReadBuffer = null;
    readBuffer = readBufferRef.get();
   }
   if (readBuffer == null) {
    readBuffer = new byte[8192];
    readBufferRef = new WeakReference<byte[]>(readBuffer);
   }
  }
 
  try {
   JarFile jarFile = new JarFile(mArchiveSourcePath);
   java.security.cert.Certificate[] certs = null;
 
   Enumeration entries = jarFile.entries();
   while (entries.hasMoreElements()) {
    JarEntry je = (JarEntry) entries.nextElement();
    if (je.isDirectory()) {
     continue;
    }
    if (je.getName().startsWith("META-INF/")) {
     continue;
    }
    java.security.cert.Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
    if (false) {
     System.out.println("File " + mArchiveSourcePath + " entry " + je.getName()
         + ": certs=" + certs + " ("
         + (certs != null ? certs.length : 0) + ")");
    }
    if (localCerts == null) {
     System.err.println("Package has no certificates at entry "
         + je.getName() + "; ignoring!");
     jarFile.close();
     return;
    } else if (certs == null) {
     certs = localCerts;
    } else {
     // Ensure all certificates match.
     for (int i = 0; i < certs.length; i++) {
      boolean found = false;
      for (int j = 0; j < localCerts.length; j++) {
       if (certs[i] != null
           && certs[i].equals(localCerts[j])) {
        found = true;
        break;
       }
      }
      if (!found || certs.length != localCerts.length) {
       System.err.println("Package has mismatched certificates at entry "
           + je.getName() + "; ignoring!");
       jarFile.close();
       return; // false
      }
     }
    }
   }
 
   jarFile.close();
 
   synchronized (mSync) {
    mReadBuffer = readBufferRef;
   }
 
   if (certs != null && certs.length > 0) {
    final int N = certs.length;
     
    for (int i = 0; i < N; i++) {
     String charSig = new String(toChars(certs[i].getEncoded()));
     System.out.println("Cert#: " + i + "  Type:" + certs[i].getType()
      + "\nPublic key: " + certs[i].getPublicKey()
      + "\nHash code: " + certs[i].hashCode()
       + " / 0x" + Integer.toHexString(certs[i].hashCode())
      + "\nTo char: " + charSig);
    }
   } else {
    System.err.println("Package has no certificates; ignoring!");
    return;
   }
  } catch (CertificateEncodingException ex) {
   Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  } catch (IOException e) {
   System.err.println("Exception reading " + mArchiveSourcePath + "\n" + e);
   return;
  } catch (RuntimeException e) {
   System.err.println("Exception reading " + mArchiveSourcePath + "\n" + e);
   return;
  }
 }
 
 private static char[] toChars(byte[] mSignature) {
    byte[] sig = mSignature;
    final int N = sig.length;
    final int N2 = N*2;
    char[] text = new char[N2];
 
    for (int j=0; j<N; j++) {
      byte v = sig[j];
      int d = (v>>4)&0xf;
      text[j*2] = (char)(d >= 10 ? ('a' + d - 10) : ('0' + d));
      d = v&0xf;
      text[j*2+1] = (char)(d >= 10 ? ('a' + d - 10) : ('0' + d));
    }
 
    return text;
    }
 
 private static java.security.cert.Certificate[] loadCertificates(JarFile jarFile, JarEntry je, byte[] readBuffer) {
  try {
   // We must read the stream for the JarEntry to retrieve
   // its certificates.
   InputStream is = jarFile.getInputStream(je);
   while (is.read(readBuffer, 0, readBuffer.length) != -1) {
    // not using
   }
   is.close();
 
   return (java.security.cert.Certificate[]) (je != null ? je.getCertificates() : null);
  } catch (IOException e) {
   System.err.println("Exception reading " + je.getName() + " in "
       + jarFile.getName() + ": " + e);
  }
  return null;
 }
}

相关文章

  • 0CTF 2015 Quals CTF VEZEL Writeu

    Category: MobilePoints: 100Solves: 105Description: Everma...

  • SECCON Quals CTF 2015 Reverse-E

    Github Link 题目比较简单, 直接简单解释下不多说. Overview 不需要Overview,直接看代...

  • 记一次gdb调试学习堆内存

    题目是jarvisoj的guessbook2,似乎原题目是0ctf上的 http://rk700.github.i...

  • Sharif University Quals CTF 2014

    Github Link Markdown哪儿都好就是插图太麻烦,尽量用语言描述 Overview 题目给的是一个D...

  • 0ctf 2018 babystack

    拿到程序,栈溢出,但是溢出的不多,除此之外没有任何的泄漏函数,于是想到栈转移然后再用ret2dlsolve,可以到...

  • 0ctf部分wp

    大佬说太难不用看正好作业也没写完所以就没看,乖巧.jpg然后作业写到一半发现手动写hill的逆矩阵是不会带来快乐的...

  • 0ctf 2017 xss

    博客文章迁移: 2017-03-21 12:18 第一次参加ctf…真的是好醉…我xss做的本来就少,基础知识不牢...

  • 从入门到遗忘:double free —— 2015 0CTF

    emmmm之前一直在入门windows,好久都没怎么碰linux了,逛大神博客碰到了这道题的wp,拿来复习下。 好...

  • 0ops CTF/0CTF writeup

    ×00 0CTF 『第一届0ops信息安全技术挑战赛,即0ops Capture The Flag,以下简称0CT...

  • [0CTF 2016]piapiapia之愚见

    今天在buuctf上尝试了一下[0CTF 2016]piapiapia之愚见这个题目,点进去之后是登录界面和一张猫...

网友评论

      本文标题:0CTF 2015 Quals CTF VEZEL Writeu

      本文链接:https://www.haomeiwen.com/subject/oacnextx.html