cfsolve 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +26 -6
- data/UPSTREAM.md +23 -8
- data/lib/cfsolve/profiles/safari-26-ios/answers.json +805 -797
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +909 -899
- data/lib/cfsolve/version.rb +2 -2
- data/lib/cfsolve.rb +22 -11
- data/vendor/cfsolve/README.md +5 -53
- data/vendor/cfsolve/examples/listing_dump.rs +24 -0
- data/vendor/cfsolve/examples/probe_similarity.rs +37 -0
- data/vendor/cfsolve/examples/rebase_reference.rs +96 -0
- data/vendor/cfsolve/examples/reread_capture.rs +31 -0
- data/vendor/cfsolve/examples/turnstile_smoke.rs +24 -3
- data/vendor/cfsolve/profiles/safari-26-ios/answers.json +805 -797
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +909 -899
- data/vendor/cfsolve/src/capture/sessions.rs +88 -4
- data/vendor/cfsolve/src/capture.rs +1 -0
- data/vendor/cfsolve/src/deobfuscate/ast.rs +16 -0
- data/vendor/cfsolve/src/deobfuscate/control_flow.rs +1 -1
- data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +33 -0
- data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +24 -4
- data/vendor/cfsolve/src/embedding_page/extra_params.rs +10 -113
- data/vendor/cfsolve/src/embedding_page/page.rs +70 -99
- data/vendor/cfsolve/src/session/initial.rs +6 -7
- data/vendor/cfsolve/src/session/probes.rs +0 -1
- data/vendor/cfsolve/src/stage2/analysis/analyze.rs +4 -33
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +9 -17
- data/vendor/cfsolve/src/stage2/benchmark.rs +42 -62
- data/vendor/cfsolve/src/stage2/call_stack.rs +133 -227
- data/vendor/cfsolve/src/stage2/challenge_page.rs +10 -3
- data/vendor/cfsolve/src/stage2/probes/dates.rs +0 -44
- data/vendor/cfsolve/src/stage2/probes/parent_info.rs +345 -61
- data/vendor/cfsolve/src/stage2/probes/performance.rs +42 -5
- data/vendor/cfsolve/src/stage2/probes/stack.rs +45 -117
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +7 -76
- data/vendor/cfsolve/src/stage2/probes.rs +0 -1
- data/vendor/cfsolve/src/stage2/reference.json +1 -1
- data/vendor/cfsolve/src/stage2/reference.rs +70 -115
- data/vendor/cfsolve/src/stage2/registry.rs +6 -11
- data/vendor/cfsolve/src/stage2/replay.rs +3 -34
- data/vendor/cfsolve/src/stage2/stylesheets.rs +0 -35
- data/vendor/cfsolve/src/stage2/trace.rs +1 -1
- data/vendor/cfsolve/src/stage2/vocabulary.rs +6 -111
- data/vendor/cfsolve/src/stage2.rs +0 -1
- data/vendor/cfsolve/src/vm/dataflow.rs +15 -6
- data/vendor/cfsolve/src/vm/disassemble.rs +5 -68
- data/vendor/cfsolve/src/vm/encoded_strings.rs +1553 -0
- data/vendor/cfsolve/src/vm/extract.rs +193 -343
- data/vendor/cfsolve/src/vm/interpret/access.rs +2 -10
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +0 -13
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +28 -43
- data/vendor/cfsolve/src/vm/interpret/mix32.rs +216 -86
- data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +42 -21
- data/vendor/cfsolve/src/vm/interpret/pattern.rs +272 -100
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +259 -36
- data/vendor/cfsolve/src/vm/interpret/run.rs +0 -4
- data/vendor/cfsolve/src/vm/machine.rs +14 -70
- data/vendor/cfsolve/src/vm/output.rs +3 -5
- data/vendor/cfsolve/src/vm/registers.rs +26 -46
- data/vendor/cfsolve/src/vm/session.rs +11 -9
- data/vendor/cfsolve/src/vm.rs +1 -1
- metadata +6 -12
- data/lib/cfsolve/profiles/chrome-157-macos/answers.json +0 -4777
- data/lib/cfsolve/profiles/chrome-157-macos.json +0 -613
- data/vendor/cfsolve/profiles/chrome-157-macos/answers.json +0 -4777
- data/vendor/cfsolve/profiles/chrome-157-macos.json +0 -613
- data/vendor/cfsolve/src/stage2/fixtures/encoded_benchmark_worker.js +0 -1
- data/vendor/cfsolve/src/stage2/probes/parent_info_array.rs +0 -326
- data/vendor/cfsolve/src/stage2/value_labels.rs +0 -185
- data/vendor/cfsolve/src/vm/encoded_names.rs +0 -635
- data/vendor/cfsolve/src/vm/fixtures/free_functions/README.md +0 -9
- data/vendor/cfsolve/src/vm/fixtures/free_functions/machine.js +0 -7438
- data/vendor/cfsolve/src/vm/fixtures/free_functions/program.base64 +0 -1
data/lib/cfsolve/version.rb
CHANGED
data/lib/cfsolve.rb
CHANGED
|
@@ -14,7 +14,7 @@ module Cfsolve
|
|
|
14
14
|
|
|
15
15
|
# Reusable browser configuration. Each call runs with its own connections and cookies.
|
|
16
16
|
class Browser
|
|
17
|
-
DEFAULT_PROFILE = File.expand_path("../cfsolve/profiles/
|
|
17
|
+
DEFAULT_PROFILE = File.expand_path("../cfsolve/profiles/safari-26-ios.json", __FILE__).freeze
|
|
18
18
|
EXECUTABLE = File.expand_path("../cfsolve/cfsolve-engine", __FILE__).freeze
|
|
19
19
|
ERRORS = {
|
|
20
20
|
"configuration" => ConfigurationError,
|
|
@@ -73,23 +73,34 @@ module Cfsolve
|
|
|
73
73
|
|
|
74
74
|
request[:configuration] = JSON.parse(@configuration)
|
|
75
75
|
request[:timeout] = timeout
|
|
76
|
+
Timeout.timeout(timeout, TimeoutError, "The solver exceeded its deadline") do
|
|
77
|
+
attempts = 0
|
|
78
|
+
begin
|
|
79
|
+
attempts += 1
|
|
80
|
+
execute(request)
|
|
81
|
+
rescue UnsupportedError
|
|
82
|
+
retry if attempts < 3
|
|
83
|
+
raise
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def execute(request)
|
|
76
89
|
child_input, input = IO.pipe
|
|
77
90
|
output, child_output = IO.pipe
|
|
78
91
|
pid = Process.spawn(EXECUTABLE, in: child_input, out: child_output, err: File::NULL)
|
|
79
92
|
status = nil
|
|
80
93
|
child_input.close
|
|
81
94
|
child_output.close
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
raise ERRORS.fetch(error.fetch("kind"), Error), error.fetch("message")
|
|
90
|
-
end
|
|
91
|
-
result
|
|
95
|
+
input.write(JSON.generate(request))
|
|
96
|
+
input.close
|
|
97
|
+
result = JSON.parse(output.read)
|
|
98
|
+
_, status = Process.wait2(pid)
|
|
99
|
+
raise Error, "The solver process failed" unless status.success?
|
|
100
|
+
if (error = result["error"])
|
|
101
|
+
raise ERRORS.fetch(error.fetch("kind"), Error), error.fetch("message")
|
|
92
102
|
end
|
|
103
|
+
result
|
|
93
104
|
rescue Errno::ENOENT
|
|
94
105
|
raise ConfigurationError, "The cfsolve executable is missing; reinstall the gem", cause: nil
|
|
95
106
|
rescue JSON::ParserError, IOError, Errno::EPIPE
|
data/vendor/cfsolve/README.md
CHANGED
|
@@ -10,10 +10,8 @@ fetch or the HTML of the page.
|
|
|
10
10
|
|
|
11
11
|
## Browser profiles
|
|
12
12
|
|
|
13
|
-
cfsolve impersonates a specific browser, described by a profile file.
|
|
14
|
-
|
|
15
|
-
Hellenic Heritage on November 12, 2026. The older `profiles/safari-26-ios.json`
|
|
16
|
-
is retained, but its measurements do not pass the current Hellenic challenge.
|
|
13
|
+
cfsolve impersonates a specific browser, described by a profile file. One is
|
|
14
|
+
included: `profiles/safari-26-ios.json` (Safari on iPhone).
|
|
17
15
|
|
|
18
16
|
Each profile references recorded responses to the challenge's browser checks,
|
|
19
17
|
stored as JSON in a directory. Keep each profile with its directory when you
|
|
@@ -23,52 +21,6 @@ set to the address of a running `capture-proxy`, which records the decoded
|
|
|
23
21
|
payloads sent to Cloudflare. Currently only Safari and Chrome(ium) profile
|
|
24
22
|
types are supported.
|
|
25
23
|
|
|
26
|
-
### November 2026 compatibility fix
|
|
27
|
-
|
|
28
|
-
Cloudflare build `7c7fee70a876` moved its VM runner and register helpers out of the
|
|
29
|
-
interpreter class, introduced per-probe string decoders and a positional parent-page
|
|
30
|
-
message, and changed fingerprint result formats. The fork recovers those structures,
|
|
31
|
-
translates randomized font and permission labels, and refreshes page-dependent
|
|
32
|
-
results. Captured VM and worker fixtures cover the parser changes.
|
|
33
|
-
|
|
34
|
-
Use the updated engine **and** the Chrome 157 profile together. The previous Chrome
|
|
35
|
-
156 measurements still fail even after the VM can execute the new challenge. A
|
|
36
|
-
prebuilt Ruby gem must be rebuilt against this fork; changing only its profile does
|
|
37
|
-
not replace its embedded native engine.
|
|
38
|
-
|
|
39
|
-
This repeatable check exercises the public library API, uses a fresh challenge on
|
|
40
|
-
every attempt, enforces the application's 30-second timeout, and prints only token
|
|
41
|
-
lengths and timings:
|
|
42
|
-
|
|
43
|
-
```sh
|
|
44
|
-
cargo run --release --locked --example turnstile_smoke -- \
|
|
45
|
-
profiles/chrome-157-macos.json https://tickets.hh.gr/en/sign-in \
|
|
46
|
-
0x4AAAAAACzgjQig4CtRf0fT 10
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
The private repository's CI runs this check on Linux alongside tests and Clippy.
|
|
50
|
-
Successful solves verify token issuance; they do not sign in to a Hellenic account
|
|
51
|
-
or deploy the engine to Dashboard. Browser profiles may need recapture when
|
|
52
|
-
Cloudflare changes the probes again.
|
|
53
|
-
|
|
54
|
-
### Audit decisions
|
|
55
|
-
|
|
56
|
-
The compatibility fix keeps both VM calling conventions, but resolves the VM class
|
|
57
|
-
and its register accessors from the installed runner. Unrelated `run` methods no
|
|
58
|
-
longer influence discovery. Captured decoders and property names are only folded
|
|
59
|
-
when their lexical binding is immutable; an unknown reassignment prevents folding.
|
|
60
|
-
|
|
61
|
-
Serialized JSON results use the same label translation as ordinary probe records.
|
|
62
|
-
The solver no longer guesses how to convert an old profile's permission-result
|
|
63
|
-
schema into the current schema. Use the freshly captured Chrome profile above;
|
|
64
|
-
profiles describe observed browser results, not a compatibility layer between
|
|
65
|
-
different challenge formats.
|
|
66
|
-
|
|
67
|
-
The audit also removed the one-off `inspect_initial` and `check_profile_names`
|
|
68
|
-
investigation examples. Keep `turnstile_smoke` for repeatable public API validation.
|
|
69
|
-
The replay session's parent-page data is internal and comes from the same typed
|
|
70
|
-
page signals as the loader message, so the two cannot be supplied independently.
|
|
71
|
-
|
|
72
24
|
## Building
|
|
73
25
|
|
|
74
26
|
You need the Rust version pinned in `rust-toolchain.toml`, plus CMake, a C/C++
|
|
@@ -82,7 +34,7 @@ cargo build --release --bin challenge
|
|
|
82
34
|
|
|
83
35
|
```sh
|
|
84
36
|
./target/release/challenge --page 'https://example.com/login' /tmp/solve \
|
|
85
|
-
--solve --fingerprint profiles/
|
|
37
|
+
--solve --fingerprint profiles/safari-26-ios.json
|
|
86
38
|
```
|
|
87
39
|
|
|
88
40
|
On success it prints the token (or `cf_clearance=...`) and sends progress
|
|
@@ -96,7 +48,7 @@ it fails on a challenge page.
|
|
|
96
48
|
|
|
97
49
|
```sh
|
|
98
50
|
./target/release/challenge --page 'https://example.com/login' /tmp/solve \
|
|
99
|
-
--solve --fingerprint profiles/
|
|
51
|
+
--solve --fingerprint profiles/safari-26-ios.json \
|
|
100
52
|
--sitekey 'SITEKEY' --action 'login' --cdata 'CUSTOM_DATA'
|
|
101
53
|
```
|
|
102
54
|
|
|
@@ -138,7 +90,7 @@ use cfsolve::{Browser, Options, PageSource, Turnstile};
|
|
|
138
90
|
|
|
139
91
|
#[tokio::main]
|
|
140
92
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
141
|
-
let browser = Browser::read("/path/to/cfsolve/profiles/
|
|
93
|
+
let browser = Browser::read("/path/to/cfsolve/profiles/safari-26-ios.json")?;
|
|
142
94
|
let options = Options::default();
|
|
143
95
|
|
|
144
96
|
let turnstile = Turnstile {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//! Temporary: `listing_dump <deobfuscated.js> <program base64 file>` prints the full listing.
|
|
2
|
+
|
|
3
|
+
use std::time::Instant;
|
|
4
|
+
use std::{env, fs};
|
|
5
|
+
|
|
6
|
+
use anyhow::Result;
|
|
7
|
+
use base64::Engine;
|
|
8
|
+
use base64::engine::general_purpose::STANDARD;
|
|
9
|
+
use cfsolve::script::Source;
|
|
10
|
+
|
|
11
|
+
fn main() -> Result<()> {
|
|
12
|
+
let arguments: Vec<String> = env::args().skip(1).collect();
|
|
13
|
+
let text = fs::read_to_string(&arguments[0])?;
|
|
14
|
+
let program = STANDARD.decode(fs::read_to_string(&arguments[1])?.trim())?;
|
|
15
|
+
let source = Source::try_new(&text)?;
|
|
16
|
+
let machine = source.machine()?;
|
|
17
|
+
let began = Instant::now();
|
|
18
|
+
let listing = machine.disassemble_from(&program, &[machine.entry()], &["cf-chl-peek"])?;
|
|
19
|
+
eprintln!("disassemble: {:?}", began.elapsed());
|
|
20
|
+
if arguments.get(2).is_none_or(|flag| flag != "--quiet") {
|
|
21
|
+
println!("{listing:#?}");
|
|
22
|
+
}
|
|
23
|
+
Ok(())
|
|
24
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//! Show each captured probe's closest reference probe and its non-name strings, to see why
|
|
2
|
+
//! probes of a new build fail to pair.
|
|
3
|
+
//! Usage: probe_similarity <capture.json> [probe index...]
|
|
4
|
+
|
|
5
|
+
use std::env;
|
|
6
|
+
use std::path::Path;
|
|
7
|
+
|
|
8
|
+
use anyhow::{Context, Result};
|
|
9
|
+
use cfsolve::capture::CapturedSession;
|
|
10
|
+
use cfsolve::stage2::analysis;
|
|
11
|
+
|
|
12
|
+
fn main() -> Result<()> {
|
|
13
|
+
let mut arguments = env::args().skip(1);
|
|
14
|
+
let path = arguments.next().context("supply a capture JSON file")?;
|
|
15
|
+
let detail: Vec<usize> = arguments.filter_map(|text| text.parse().ok()).collect();
|
|
16
|
+
let capture = CapturedSession::read(Path::new(&path))?;
|
|
17
|
+
let analysis = analysis::analyze(&capture.source()?, &capture.program()?)?;
|
|
18
|
+
let plan = analysis.plan();
|
|
19
|
+
let vocabulary = plan.vocabulary();
|
|
20
|
+
for (position, probe) in plan.probes().iter().enumerate() {
|
|
21
|
+
let candidate = vocabulary.candidate(position);
|
|
22
|
+
println!(
|
|
23
|
+
"{}\tpartner {:?}\tbest {:?}\t{} strings",
|
|
24
|
+
probe.index,
|
|
25
|
+
vocabulary.partner(position),
|
|
26
|
+
candidate.map(|candidate| (candidate.reference, candidate.similarity)),
|
|
27
|
+
probe.features.len(),
|
|
28
|
+
);
|
|
29
|
+
if detail.contains(&probe.index) {
|
|
30
|
+
println!(" {:?}", probe.features);
|
|
31
|
+
let payload = capture.probe_payload().ok();
|
|
32
|
+
let record = payload.and_then(|payload| payload.get(&probe.index.to_string()));
|
|
33
|
+
println!(" sent {}", serde_json::to_string(&record)?);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
Ok(())
|
|
37
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
//! Rebuild the reference from a capture of a new build, keeping the reference probe numbers.
|
|
2
|
+
//! Usage: rebase_reference <capture.json> <old reference.json> <reference.rs> <new reference.json>
|
|
3
|
+
//!
|
|
4
|
+
//! Each reference probe becomes the capture's probe paired with it, or the capture's probe of
|
|
5
|
+
//! the same family when that family is recognized without pairing; a family the build no longer
|
|
6
|
+
//! has keeps its old strings. Prints each hex name `reference.rs` declares with the capture's name
|
|
7
|
+
//! for it, through the vocabulary of every probe that mentions it, and `?` where a probe does not
|
|
8
|
+
//! translate it, so the declarations can be moved to the new reference.
|
|
9
|
+
|
|
10
|
+
use std::collections::{BTreeMap, BTreeSet};
|
|
11
|
+
use std::path::Path;
|
|
12
|
+
use std::{env, fs};
|
|
13
|
+
|
|
14
|
+
use anyhow::{Context, Result};
|
|
15
|
+
use cfsolve::capture::CapturedSession;
|
|
16
|
+
use cfsolve::stage2::analysis;
|
|
17
|
+
use cfsolve::stage2::registry::Kind;
|
|
18
|
+
use serde_json::{Value, json};
|
|
19
|
+
|
|
20
|
+
fn main() -> Result<()> {
|
|
21
|
+
let arguments: Vec<String> = env::args().skip(1).collect();
|
|
22
|
+
let [capture, old, declarations, new] = arguments.as_slice() else {
|
|
23
|
+
anyhow::bail!("supply capture.json, the old reference.json, reference.rs and an output");
|
|
24
|
+
};
|
|
25
|
+
let capture = CapturedSession::read(Path::new(capture))?;
|
|
26
|
+
let analysis = analysis::analyze(&capture.source()?, &capture.program()?)?;
|
|
27
|
+
let plan = analysis.plan();
|
|
28
|
+
let vocabulary = plan.vocabulary();
|
|
29
|
+
let old: Value = serde_json::from_str(&fs::read_to_string(old)?)?;
|
|
30
|
+
let old_probes = old["probes"].as_array().context("no reference probes")?;
|
|
31
|
+
// Each reference probe's session probe position.
|
|
32
|
+
let mut positions: BTreeMap<usize, usize> = BTreeMap::new();
|
|
33
|
+
for (position, probe) in plan.probes().iter().enumerate() {
|
|
34
|
+
let reference = vocabulary.partner(position).or_else(|| {
|
|
35
|
+
let kind = probe.operation.as_ref()?.kind();
|
|
36
|
+
match kind.references() {
|
|
37
|
+
[reference] => Some(*reference),
|
|
38
|
+
_ => None,
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if let Some(reference) = reference {
|
|
42
|
+
anyhow::ensure!(
|
|
43
|
+
positions.insert(reference, position).is_none(),
|
|
44
|
+
"two probes stand for reference probe {reference}"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
let mut probes = Vec::new();
|
|
49
|
+
for (number, old_probe) in (1..).zip(old_probes) {
|
|
50
|
+
if let Some(&position) = positions.get(&number) {
|
|
51
|
+
probes.push(json!(plan.probes()[position].features));
|
|
52
|
+
} else {
|
|
53
|
+
eprintln!(
|
|
54
|
+
"reference probe {number} ({}) has no probe in this build; keeping its strings",
|
|
55
|
+
Kind::from_reference(number).map_or("?".into(), |kind| kind.to_string())
|
|
56
|
+
);
|
|
57
|
+
probes.push(old_probe.clone());
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
let build = capture
|
|
61
|
+
.iframe_html()
|
|
62
|
+
.split("/turnstile/v0/g/")
|
|
63
|
+
.nth(1)
|
|
64
|
+
.and_then(|rest| rest.get(..12))
|
|
65
|
+
.unwrap_or("unknown");
|
|
66
|
+
let rebuilt = json!({"build": build, "probes": probes});
|
|
67
|
+
fs::write(new, serde_json::to_string(&rebuilt)?)?;
|
|
68
|
+
|
|
69
|
+
// Translate each declared name through the probes that mention it.
|
|
70
|
+
let declarations = fs::read_to_string(declarations)?;
|
|
71
|
+
let declared: BTreeSet<&str> = declarations
|
|
72
|
+
.split('"')
|
|
73
|
+
.filter(|text| text.len() == 25 && text.starts_with('_'))
|
|
74
|
+
.filter(|text| text[1..].bytes().all(|byte| byte.is_ascii_hexdigit()))
|
|
75
|
+
.collect();
|
|
76
|
+
for name in declared {
|
|
77
|
+
let mut translations = BTreeSet::new();
|
|
78
|
+
for (number, old_probe) in (1..).zip(old_probes) {
|
|
79
|
+
let Some(&position) = positions.get(&number) else {
|
|
80
|
+
continue;
|
|
81
|
+
};
|
|
82
|
+
let strings = old_probe.as_array();
|
|
83
|
+
if strings.is_some_and(|strings| strings.iter().any(|text| text == name)) {
|
|
84
|
+
let session = vocabulary.to_session(position, name);
|
|
85
|
+
translations.insert(if session == name {
|
|
86
|
+
format!("?@{number}")
|
|
87
|
+
} else {
|
|
88
|
+
session.to_owned()
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
let translations: Vec<String> = translations.into_iter().collect();
|
|
93
|
+
println!("{name} {}", translations.join(" "));
|
|
94
|
+
}
|
|
95
|
+
Ok(())
|
|
96
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//! Read the payloads of capture-proxy sessions logged without them, as when the proxy could not
|
|
2
|
+
//! extract a session's parameters, and write completed copies of the sessions.
|
|
3
|
+
//! Usage: reread_capture <capture-dir> <output-dir>
|
|
4
|
+
//!
|
|
5
|
+
//! Reads each `sessions/session-*` under the capture directory and writes the completed session
|
|
6
|
+
//! under `<output-dir>/sessions/` with the same name. The capture directory is left unchanged.
|
|
7
|
+
|
|
8
|
+
use std::path::PathBuf;
|
|
9
|
+
use std::{env, fs};
|
|
10
|
+
|
|
11
|
+
use anyhow::{Context, Result};
|
|
12
|
+
use cfsolve::capture;
|
|
13
|
+
|
|
14
|
+
fn main() -> Result<()> {
|
|
15
|
+
let mut arguments = env::args().skip(1);
|
|
16
|
+
let directory = PathBuf::from(arguments.next().context("supply a capture directory")?);
|
|
17
|
+
let output = PathBuf::from(arguments.next().context("supply an output directory")?);
|
|
18
|
+
let mut sessions: Vec<PathBuf> = fs::read_dir(directory.join("sessions"))?
|
|
19
|
+
.map(|entry| Ok(entry?.path()))
|
|
20
|
+
.collect::<Result<_>>()?;
|
|
21
|
+
sessions.sort();
|
|
22
|
+
for session in sessions {
|
|
23
|
+
let name = session.file_name().context("a session has no name")?;
|
|
24
|
+
let out = output.join("sessions").join(name);
|
|
25
|
+
match capture::reread_session(&session, &out) {
|
|
26
|
+
Ok(count) => println!("{}: {count} payloads", session.display()),
|
|
27
|
+
Err(error) => println!("{}: {error:#}", session.display()),
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
Ok(())
|
|
31
|
+
}
|
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
//! Repeat fresh widget solves without printing
|
|
1
|
+
//! Repeat fresh widget solves without printing tokens.
|
|
2
2
|
//! Usage: turnstile_smoke <profile.json> <page-url> <sitekey> [attempts]
|
|
3
|
+
//! CFSOLVE_SMOKE_CAPTURE optionally saves anonymous challenge diagnostics.
|
|
3
4
|
|
|
4
5
|
use std::{
|
|
5
6
|
env,
|
|
7
|
+
fs,
|
|
8
|
+
path::PathBuf,
|
|
9
|
+
sync::Arc,
|
|
6
10
|
time::{Duration, Instant},
|
|
7
11
|
};
|
|
8
12
|
|
|
9
13
|
use anyhow::{Context, Result, ensure};
|
|
10
|
-
use cfsolve::{Browser, Options, PageSource, Turnstile, Widget};
|
|
14
|
+
use cfsolve::{Browser, Options, PageSource, Sink, Turnstile, Widget};
|
|
15
|
+
|
|
16
|
+
struct Capture(PathBuf);
|
|
17
|
+
|
|
18
|
+
impl Sink for Capture {
|
|
19
|
+
fn artifact(&self, name: &str, contents: &[u8]) -> Result<()> {
|
|
20
|
+
fs::write(self.0.join(name), contents)?;
|
|
21
|
+
Ok(())
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fn progress(&self, _: &str) {}
|
|
25
|
+
}
|
|
11
26
|
|
|
12
27
|
#[tokio::main]
|
|
13
28
|
async fn main() -> Result<()> {
|
|
@@ -23,6 +38,12 @@ async fn main() -> Result<()> {
|
|
|
23
38
|
let browser = Browser::read(&profile)?;
|
|
24
39
|
let started = Instant::now();
|
|
25
40
|
for attempt in 1..=attempts {
|
|
41
|
+
let mut options = Options::default();
|
|
42
|
+
if let Some(root) = env::var_os("CFSOLVE_SMOKE_CAPTURE") {
|
|
43
|
+
let directory = PathBuf::from(root).join(format!("attempt-{attempt}"));
|
|
44
|
+
fs::create_dir_all(&directory)?;
|
|
45
|
+
options.sink = Some(Arc::new(Capture(directory)));
|
|
46
|
+
}
|
|
26
47
|
let tick = Instant::now();
|
|
27
48
|
let widget = Turnstile {
|
|
28
49
|
url: url.clone(),
|
|
@@ -35,7 +56,7 @@ async fn main() -> Result<()> {
|
|
|
35
56
|
};
|
|
36
57
|
let token = tokio::time::timeout(
|
|
37
58
|
Duration::from_secs(30),
|
|
38
|
-
browser.solve_turnstile(widget, &
|
|
59
|
+
browser.solve_turnstile(widget, &options),
|
|
39
60
|
)
|
|
40
61
|
.await
|
|
41
62
|
.with_context(|| format!("attempt {attempt} exceeded 30 seconds"))?
|