Skip to content

Feature/dirty cow #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
/app/src/main/libs/
/app/src/main/obj/
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
app/.externalNativeBuild/
14 changes: 14 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.

cmake_minimum_required(VERSION 3.4.1)

# set binary output folder to libs folder
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}")

add_library( dirtyCow
SHARED
src/main/jni/dirtycow.c )
target_link_libraries( dirtyCow
log)
15 changes: 10 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
compileSdkVersion 25
buildToolsVersion "24.0.1"

defaultConfig {
applicationId "com.nowsecure.android.vts"
minSdkVersion 15
targetSdkVersion 24
targetSdkVersion 25
versionCode 13
versionName "v.13"
}
Expand Down Expand Up @@ -38,6 +38,11 @@ android {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}

repositories {
Expand All @@ -46,9 +51,9 @@ repositories {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:cardview-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.evernote:android-job:1.0.8'
compile 'com.github.paolorotolo:appintro:4.0.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/assets/vuln_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,32 @@
"https://android.googlesource.com/platform/system/core.git/+/d167d5eabc794ba4ddef1a2900eb729720da84a2"
],
"cvedate": "12/10/2015"
},
"CVE-2016-5195": {
"cve": "CVE-2016-5195",
"altnames": [
"CVE-2016-5195",
"DirtyCow",
"DirtyC0w"
],
"description": "A race condition was found in the way the Linux kernel's memory subsystem handled the copy-on-write (COW) breakage of private read-only memory mappings. An unprivileged, local user could use this flaw to gain write access to otherwise read-only memory mappings and thus increase their privileges on the system.",
"impact":
"An unprivileged local user could use this flaw to gain write access to otherwise read-only memory mappings and thus increase their privileges on the system. This flaw allows an attacker with a local system account to modify on-disk binaries, bypassing the standard permission mechanisms that would prevent modification without an appropriate permission set."
,
"external_links": [
"https://dirtycow.ninja/",
"https://github.com/dirtycow/dirtycow.github.io/wiki/VulnerabilityDetails",
"https://bugzilla.redhat.com/show_bug.cgi?id=1384344",
"https://bugs.gentoo.org/show_bug.cgi?id=597624"
],
"cvssv2": 6.9,
"patch": [
"https://github.com/kcgthb/RHEL6.x-COW",
"https://review.cyanogenmod.org/#/c/172707/",
"https://review.cyanogenmod.org/#/c/167403/",
"Android security patch level 2016-11-06"
],
"cvedate": "10/20/2016"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import fuzion24.device.vulnerability.vulnerabilities.kernel.CVE_2014_3153;
import fuzion24.device.vulnerability.vulnerabilities.kernel.CVE_2014_4943;
import fuzion24.device.vulnerability.vulnerabilities.kernel.CVE_2015_3636;
import fuzion24.device.vulnerability.vulnerabilities.kernel.CVE_2016_5195;
import fuzion24.device.vulnerability.vulnerabilities.system.CVE20151528;
import fuzion24.device.vulnerability.vulnerabilities.system.CVE20153860;
import fuzion24.device.vulnerability.vulnerabilities.system.CVE_2016_0807;
Expand Down Expand Up @@ -61,6 +62,7 @@ public static List<VulnerabilityTest> getTests(Context ctx){
allTests.add(new CVE_2015_6616());
allTests.add(new CVE20153860());
allTests.add(new CVE_2016_0807());
allTests.add(new CVE_2016_5195()); // DirtyCow vulnerability

List<VulnerabilityTest> filteredTest = new ArrayList<>();
String cpuArch1 = SystemUtils.propertyGet(ctx, "ro.product.cpu.abi");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package fuzion24.device.vulnerability.vulnerabilities.kernel;

import android.content.Context;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

import fuzion24.device.vulnerability.util.CPUArch;
import fuzion24.device.vulnerability.vulnerabilities.VulnerabilityTest;

/**
* Created by Till Busse on 21/11/16.
* Java implementation to test dirtyCow vulnerability.
*/

public class CVE_2016_5195 implements VulnerabilityTest {
static {
System.loadLibrary("dirtyCow");
}
private final String file1Name = "file1";
private final String file2Name = "file2";
private final String file1Content = "This is File one.";
private final String file2Content = "Mo0h";
@Override
public String getCVEorID() {
return "CVE-2016-5195";
}

private native int runDirtyCow(Object [] paths);

@Override
public boolean isVulnerable(Context context) throws Exception {
try{

List<Object> paths = createFiles(context);
boolean isWritten = checkFileContent(context, file1Name, file1Content);
if (!isWritten)
throw new Exception("Error running test. File could not be created with specific content");

int checkVal = runDirtyCow(paths.toArray());
if (checkVal == 0){
isWritten = checkFileContent(context, file1Name, file2Content);
return isWritten;
}else {
throw new Exception("Error running test. Errno: " + checkVal);
}
}finally {
// delete files when done
File file;
file = new File(context.getFilesDir(), file1Name);
file.delete();
file = new File(context.getFilesDir(), file1Name);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be file2Name I think (yeah, I know that this repo is pretty dead, but still 😉 )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks =D

file.delete();
}
}

@Override
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<>();
archs.add(CPUArch.ALL);
return archs;
}

private List<Object> createFiles(Context context){
List<Object> paths = new ArrayList<>();
paths.add(0, context.getFilesDir().getAbsolutePath() + "/" + file1Name);
paths.add(1, context.getFilesDir().getAbsolutePath() + "/" + file2Name);
FileOutputStream outputStream;

try {
outputStream = context.openFileOutput(file1Name, Context.MODE_PRIVATE);
outputStream.write(file1Content.getBytes());
outputStream = context.openFileOutput(file2Name, Context.MODE_PRIVATE);
outputStream.write(file2Content.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
return paths;
}
private boolean checkFileContent(Context context, String filename, String content){
File fileCheck = context.getFilesDir();
//Get the text file
File file = new File(fileCheck,filename);
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;

while ((line = br.readLine()) != null) {
text.append(line);
//text.append('\n');
}
br.close();
}catch (IOException e) {
e.printStackTrace();
}
return content.equals(text.substring(0, content.length()));
}
}
13 changes: 13 additions & 0 deletions app/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,16 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/

include $(BUILD_EXECUTABLE)
################################

################################
#include $(CLEAR_VARS)
#
#LOCAL_MODULE := dirtyCow
#LOCAL_SRC_FILES := dirtycow.c
#LOCAL_LDFLAGS += -llog
##LOCAL_CFLAGS += -DDEBUG
#LOCAL_CFLAGS += -fPIE
#LOCAL_LDFLAGS += -fPIE -pie
#
#include $(BUILD_SHARED_LIBRARY)
################################
Loading