您可以从 UUID 中提取什么类型的数据?

发布于 2024-08-10 22:10:10 字数 65 浏览 9 评论 0原文

我知道我们可以轻松提取 uuid 版本号。有没有可靠的方法来提取时间戳、MAC 地址等信息?

谢谢!

I know that we could easily extract the uuid version number. Is there a reliable way to extract information like timestamp, MAC address?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

辞取 2024-08-17 22:10:10

符合标准的 UUID 可能是多个变体之一,它看起来像这样:

AAAAAAAA-BBBB-CCCC-DDDD-FFFFFFFFFFFF

DDDD 部分的第一个(十六进制)数字决定了变体。

如果它是 8,9,A,B 之一,则符合当前规范
(0-7保留用于向后兼容,C、D保留给Microsoft,E、F保留供将来使用)

如果符合当前规范,请检查确定UUID版本的CCCC部分的第一位数字:

  1. 基于时间,具有唯一或随机主机标识符 (MAC)
  2. DCE 安全版本(具有 POSIX UID)
  3. 基于名称(MD5 哈希)
  4. 随机
  5. 基于

名称(SHA-1 哈希)版本 4 是随机选择的。

版本 3 和版本 5 是通过散列并丢弃一些位生成的,这意味着您基本上没有机会从中恢复任何信息。有关如何构建它的详细信息,请参阅 RFC4122UUID 生成器网页

我找不到任何版本 2 UUID,因此我没有检查如何提取数据。

版本 1 是根据时间戳和当前主机 MAC 地址生成的。
(如果您设置 MAC 地址的“广播/多播”位,该标准还允许使用随机地址。)

以下 perl 片段从版本 1 uuid 解析 MAC 地址和时间:

my $uuid="AAAAAAAA-BBBB-CCCC-DDDD-FFFFFFFFFFFF";
$uuid=~tr/-//d;
my $time_low=hex substr($uuid,2* 0,2*4);
my $time_mid=hex substr($uuid,2* 4,2*2);
my $version =hex substr($uuid,2* 6,1);
my $time_hi =hex substr($uuid,2* 6+1,2*2-1);

my $time=($time_hi*(2**16)+$time_mid)*(2**32)+$time_low;
my $epoc=int($time /10000000) - 12219292800;
my $nano=$time-int($time/10000000)*10000000;

my $clk_hi  =hex substr($uuid,2* 8,2*1);
my $clk_lo  =hex substr($uuid,2* 9,2*1);
my $node    =substr($uuid,2*10,2*6);

$node=~/^(..)(..)(..)(..)(..)(..)$/ || die;
$node="$1:$2:$3:$4:$5:$6";

print "time: ",scalar localtime $epoc," +",$nano/10000,"ms\n";
print "clock id: ",$clk_hi*256+$clk_lo,"\n";
print "Mac: $node\n";

my $byte=hex $1;
if(hex($1)&1){
    print "broadcast/multicast bit set.\n";
};

最后但并非最不重要的一点是,有是几个分配的 UUID,例如 GPT 分区

A standard-conforming UUID may be one of several variants, it looks like this:

AAAAAAAA-BBBB-CCCC-DDDD-FFFFFFFFFFFF

The first (hex)digit of the DDDD part determines the variant.

If it is one of 8,9,A,B it is conforming to the current spec
(0-7 are reserved for backward compatibility, C,D are reserved for Microsoft, and E,F are reserved for future use)

If it conforms to the current spec, check the first digit of the CCCC part which determines the UUID version:

  1. Time-based with unique or random host identifier (MAC)
  2. DCE Security version (with POSIX UIDs)
  3. Name-based (MD5 hash)
  4. Random
  5. Name-based (SHA-1 hash)

Version 4 is simply randomly chosen.

Version 3 and 5 are generated by hashing and throwing away some bits which means you have basically no chance in recovering any information from it. Details on how to build it can be found in RFC4122 or at the UUID Generator webpage.

I could not find any version 2 UUIDs so I didn't check how to extract the data.

Version 1 is generated from a time-stamp and current host MAC address.
(The standard also allows to use a random address instead if you set the "broadcast/multicast" bit of the MAC address.)

The following perl snipped parses the MAC address and Time from a version 1 uuid:

my $uuid="AAAAAAAA-BBBB-CCCC-DDDD-FFFFFFFFFFFF";
$uuid=~tr/-//d;
my $time_low=hex substr($uuid,2* 0,2*4);
my $time_mid=hex substr($uuid,2* 4,2*2);
my $version =hex substr($uuid,2* 6,1);
my $time_hi =hex substr($uuid,2* 6+1,2*2-1);

my $time=($time_hi*(2**16)+$time_mid)*(2**32)+$time_low;
my $epoc=int($time /10000000) - 12219292800;
my $nano=$time-int($time/10000000)*10000000;

my $clk_hi  =hex substr($uuid,2* 8,2*1);
my $clk_lo  =hex substr($uuid,2* 9,2*1);
my $node    =substr($uuid,2*10,2*6);

$node=~/^(..)(..)(..)(..)(..)(..)$/ || die;
$node="$1:$2:$3:$4:$5:$6";

print "time: ",scalar localtime $epoc," +",$nano/10000,"ms\n";
print "clock id: ",$clk_hi*256+$clk_lo,"\n";
print "Mac: $node\n";

my $byte=hex $1;
if(hex($1)&1){
    print "broadcast/multicast bit set.\n";
};

And last but not least, there are several assigned UUIDs, for example for GPT partitions.

薄荷梦 2024-08-17 22:10:10

不一定是可靠的方式,因为根据 UUID 的类型,它可能完全由随机位生成,或者基于时间戳,或者基于 MAC 地址。因此,您也许可以获得其中一些信息,但不能保证您可以获得任何信息。

官方参考是 RFC 4122,它可能会为您提供足够的信息来提取数据,尽管您可能不应该过于依赖它。

Not necessarily a reliable way, because depending on the kind of UUID it is, it may be generated totally from random bits, or be timestamp-based, or be based on the MAC address. So you may be able to get some of that information, but you can't guarantee you can get anything.

The official reference for this is RFC 4122, which should probably give you enough information to extract data, although you probably shouldn't rely on it too heavily.

难以启齿的温柔 2024-08-17 22:10:10

OSSP uuid工具可以解码所有版本的UUID。在基于 Debian 的 Linux 系统上,您可以使用 apt-get install uuid 来安装它;对于其他发行版,包名称可能不同。

要解码 UUID,请使用 -d(解码)标志:

uuid -d AAAAAAAA-BBBB-CCCC-DDDD-FFFFFFFFFFFF

对于版本 1 UUID,这给出了 MAC 地址和时间戳 - 因为这是 v1 uuid 中的内容。

The OSSP uuid tool can decode UUIDs of all versions. On Debian-based Linux systems you can use apt-get install uuid to install it; for other distributions, the package name might be different.

To decode a UUID, use the -d (decode) flag:

uuid -d AAAAAAAA-BBBB-CCCC-DDDD-FFFFFFFFFFFF

For version 1 UUIDs, this gives the MAC address and timestamp -- since that's what's in a v1 uuid.

青巷忧颜 2024-08-17 22:10:10

我知道我们可以轻松提取 uuid 版本号。有没有可靠的方法来提取时间戳、MAC 地址等信息?

是的,是的;如果 UUID 是版本 1 或版本 2(如 RFC 4122 中所述)。还有一个替代(非 RFC 4122)版本 4,称为“COMB”,其中包含可以解析的时间戳(以及随机值),并且可以显示创建日期/时间。

奖励:Mahonri Moriancumer 的 UUID 和 GUID 生成器和取证

I know that we could easily extract the uuid version number. Is there a reliable way to extract information like timestamp, MAC address?

Yes, and Yes; if the UUID is version 1 or version 2 (as described in RFC 4122). There is also an alternate (non-RFC 4122) version 4, dubbed "COMB" that includes a time-stamp (as well as random values) that can be parsed, and the creation date/time can be revealed.

Bonus: Mahonri Moriancumer's UUID and GUID Generator and Forensics.

暮倦 2024-08-17 22:10:10

如果它是版本 1 UUID,则 MAC 地址将为最后 12 位十六进制数字。

If it's a version 1 UUID, the MAC address will be the last twelve hex digits.

半步萧音过轻尘 2024-08-17 22:10:10

您可以查看 Uuid 的版本,但只有在确定 Uuid 有效的情况下才可以信任(请参阅 https://www.rfc-editor.org/rfc/rfc4122)。该版本将告诉您拥有哪种 Uuid,并使用它您可以提取特定的信息位。

You could look at the version of the Uuid, but that can only be trusted if you are sure the Uuid is valid (see https://www.rfc-editor.org/rfc/rfc4122). The version will tell you what kind of Uuid you have, and using that you can extract specific bits of information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文