使用libfaketime伪造单个应用程序的系统时钟

A bit of a back story

我的用例非常具体-我想对在基于CentOS的Docker容器中运行的Java应用程序进行一些端到端测试。 我要测试的代码依赖于日期比较:

if (happenedYesterday(event)) {
      
    foo();
} else {
      
    bar();
}

鉴于我无法修改测试数据,最简单的方法是以某种方式使应用程序认为它是昨天,使其创建事件,然后恢复原始日期,并使应用程序调用上面的代码。

The setup

Since I would like to show how I got from an idea to a working solution, I need to provide a way to reproduce all the mistakes that I've made as part of this exercise - I need an environment which is as close to the original as possible. To achieve it and also to keep the examples as simple as possible, I'll use fabric8/java-centos-openjdk8-jdk Docker image.

让我们从一个未修改的图像开始一个容器,并打开其外壳:

[me@pc ~]$ docker run --name centos -d -it fabric8/java-centos-openjdk8-jdk /bin/bash
...
[me@pc ~]$ docker exec -u 0 -it centos /bin/bash
[root@centos /]#
注意:-u 0参数使命令以root身份登录到容器(0是root的用户ID)

在本文的所有示例中,我将使用个人电脑如[me@个人电脑 ~]$指示在本地计算机上调用的命令,以及中心如[root@中心 /]#用于在容器内调用的命令。

Setting the system date in Docker - naive approach

在我幼稚的方法中,我认为此步骤就像运行以下命令之一一样简单:

[root@centos /]# date -s "15 Oct 2019 19:05"
date: cannot set date: Operation not permitted
Tue Oct 15 19:05:00 UTC 2019
[root@centos /]# hwclock --set --date "15 Oct 2019 19:05"
hwclock: Cannot access the Hardware Clock via any known method.
hwclock: Use the --debug option to see the details of our search for an access method.

不幸的是,事实并非如此。

I tried to find some workarounds, but as far as I understand, Docker reuses the clock of the host machine, so overriding the date in the container is either not doable or not easily doable123. As I'm just a casual user of Docker, I didn't want to dig deeper. However, w

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
国外网友基于faketime做的burp loader的unlimited版本. 需要一堆dll或者so. 详情见如下描述,没有分的可以去github上找. ======================== BurpUnlimited version 1.7.26 release 1.0 + Created by: mxcx@fosec.vn + Email: mxcxvn@gmail.com + Based on: BurpLoader by larry_lau + Github: https://github.com/mxcxvn/BurpUnlimited it's opensource ======================== This project is NOT intended to replace BurpLoader. It just EXTENDS BurpLoader's license! To run the project from the command line: java -javaagent:BurpUnlimited.jar -agentpath:lib/libfaketime -jar BurpUnlimited.jar or double click on BurpUnlimited.jar (set permision before) ## Notes: - There are some requirements files in lib at current folder: + burpsuite_pro_v1.7.26.jar is main object + libfaketime* Lib for hook time activation. Sourcecode is at https://github.com/faketime-java/faketime - For windows, vcredist is required: https://www.microsoft.com/en-gb/download/details.aspx?id=48145 - The folder for_windows_if_you_dont_wanna_install_vcredist is for anyone who don't wana install vcredist, please chose the file for x64 or x86, rename to vcruntime140.dll and copy to BurpUnlimited.jar's folder - To have no unexpected error, please leave all file in the folders which have not any space character (including java binary file in case not run with default java). - This version is tested run stable on MACOSX 64 bit, Ubuntu 64 bit, Windows 64 and 32 bit. If you have any error in starting, please try some ways: + Change manually your datetime to before 01/10/2017 + Build your own libfaketime, sourcecode is at https://github.com/faketime-java/faketime + Or contact me mxcxvn@gmail.com ## Hash MD5 version release 1 BurpUnlimited.jar 5cf68ad0cc2d4ee265d0da1469decf21 lib/ burpsuite_pro_v1.7.26.jar 5d1cbbebc7fb59a399ae7bcacbe05f74 libfaketime32.dll e3842711a065b672dec322c4140b950f libfaketime32.jnilib d2b62d06a972035149bfdefe1605c041 libfaketime32.so 5c2baa272037207533d74faa4291e91d libfaketime64.dll 6659efeee9698609a9ffd9ea8c9d07d1 libfaketime64.jnilib ff3dbde6a28f1c59d829cf5665c8e628 libfaketime64.so 5c2baa272037207533d74faa4291e91d for_windows_if_you_dont_wanna_install_vcredist/ vcruntime140_x32.dll b77eeaeaf5f8493189b89852f3a7a712 vcruntime140_x64.dll 6c2c88ff1b3da84b44d23a253a06c01b
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值