|
22 | 22 | + some less than optimal encodings are forced to avoid accidentally using RIP relative addressing, e.g. `lea rax, [r13]` gets encoded as `lea rax, [r13 + 0]` |
23 | 23 | - [ ] How to get the current SQL schema when all you have is lots of migrations (deltas) |
24 | 24 | - [ ] Search and replace fish function |
25 | | -- [ ] Go+Dtrace: Tips |
26 | | - ``` |
27 | | -pid$target::*DispatchMessage:entry { |
28 | | - stack_offset =656; |
29 | | - this->data=copyin(uregs[R_SP] + stack_offset, 16); |
30 | | - tracemem(this->data, 16); |
31 | | -
|
32 | | - this->body_len = *((ssize_t*)this->data+1); |
33 | | -
|
34 | | - this->body_ptr = (uint8_t**)this->data; |
35 | | -
|
36 | | - this->s = copyinstr((user_addr_t)*this->body_ptr, this->body_len); |
37 | | - printf("msg.body: %s\n", this->s); |
38 | | -} |
39 | | - ``` |
40 | | -
|
41 | | - ``` |
42 | | -$ sudo dtrace -n 'pid$target::github.com?ory?kratos*SMSBody:return{ this->body_len = uregs[1]; this->body_ptr = (uint8_t*)uregs[0]; |
43 | | -
|
44 | | - this->s = copyinstr((user_addr_t)this->body_ptr, this->body_len); |
45 | | - printf("msg.Body: %s\\n", this->s); |
46 | | - }' -p $(pgrep -a kratos) |
47 | | - ``` |
48 | | -
|
49 | | -
|
50 | | - ``` |
51 | | -
|
52 | | - 10 2968 github.com/ory/kratos/courier.(*courier).DispatchMessage:entry |
53 | | - 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef |
54 | | - 0: 80 ae c7 01 40 01 00 00 1e 00 00 00 00 00 00 00 ....@........... |
55 | | -msg.Body: Your recovery code is: 707144 |
56 | | - ``` |
57 | | -
|
58 | | - ```shell |
59 | | -$ sudo dtrace -x flowindent -n 'pid$target::*createBrowserRecoveryFlow*:entry {this->trace=1;} pid$target::*selfservice*:entry,pid$target::*selfservice*:return /this->trace/ {} pid$target::*createBrowserRecoveryFlow*:return {this->trace=0;} ' -p $(pgrep -a kratos) |
60 | | -dtrace: description 'pid$target::*createBrowserRecoveryFlow*:entry ' matched 3602 probes |
61 | | -CPU FUNCTION |
62 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.(*Handler).createBrowserRecoveryFlow-fm |
63 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.(*Handler).createBrowserRecoveryFlow |
64 | | - 10 -> github.com/ory/kratos/selfservice/strategy/code.(*Strategy).RecoveryStrategyID |
65 | | - 10 <- github.com/ory/kratos/selfservice/strategy/code.(*Strategy).RecoveryStrategyID |
66 | | - 10 -> github.com/ory/kratos/selfservice/strategy/link.(*Strategy).RecoveryStrategyID |
67 | | - 10 <- github.com/ory/kratos/selfservice/strategy/link.(*Strategy).RecoveryStrategyID |
68 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.Strategies.Strategy |
69 | | - 10 -> github.com/ory/kratos/selfservice/strategy/code.(*Strategy).RecoveryStrategyID |
70 | | - 10 <- github.com/ory/kratos/selfservice/strategy/code.(*Strategy).RecoveryStrategyID |
71 | | - 10 -> github.com/ory/kratos/selfservice/strategy/code.(*Strategy).RecoveryStrategyID |
72 | | - 10 <- github.com/ory/kratos/selfservice/strategy/code.(*Strategy).RecoveryStrategyID |
73 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.Strategies.Strategy |
74 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.NewFlow |
75 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.NewFlow.SecureRedirectUseSourceURL.func1 |
76 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.NewFlow.SecureRedirectUseSourceURL.func1 |
77 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.NewFlow.SecureRedirectAllowURLs.func2 |
78 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.NewFlow.SecureRedirectAllowURLs.func2 |
79 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.NewFlow.SecureRedirectAllowSelfServiceURLs.func3 |
80 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.NewFlow.SecureRedirectAllowSelfServiceURLs.func3 |
81 | | - 10 -> github.com/ory/kratos/selfservice/flow.AppendFlowTo |
82 | | - 10 <- github.com/ory/kratos/selfservice/flow.AppendFlowTo |
83 | | - 10 -> github.com/ory/kratos/selfservice/strategy/code.(*Strategy).NodeGroup |
84 | | - 10 <- github.com/ory/kratos/selfservice/strategy/code.(*Strategy).NodeGroup |
85 | | - 10 -> github.com/ory/kratos/selfservice/strategy/code.(*Strategy).PopulateRecoveryMethod |
86 | | - 10 <- github.com/ory/kratos/selfservice/strategy/code.(*Strategy).PopulateRecoveryMethod |
87 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.NewFlow |
88 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.(*HookExecutor).PreRecoveryHook |
89 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.(*HookExecutor).PreRecoveryHook |
90 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.(*Flow).TableName |
91 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.(*Flow).TableName |
92 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.(*Flow).TableName |
93 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.(*Flow).TableName |
94 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.(*Flow).TableName |
95 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.(*Flow).TableName |
96 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.(*Flow).TableName |
97 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.(*Flow).TableName |
98 | | - 10 -> github.com/ory/kratos/selfservice/flow.(*State).Value |
99 | | - 10 <- github.com/ory/kratos/selfservice/flow.(*State).Value |
100 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.(*Flow).AfterSave |
101 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.(*Flow).SetReturnTo |
102 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.(*Flow).SetReturnTo |
103 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.(*Flow).AfterSave |
104 | | - 10 -> github.com/ory/kratos/selfservice/flow/recovery.(*Flow).AppendTo |
105 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.(*Flow).AppendTo |
106 | | - 10 <- github.com/ory/kratos/selfservice/flow/recovery.(*Handler).createBrowserRecoveryFlow |
107 | | - ``` |
108 | | -
|
109 | | - ``` |
110 | | -$ sudo dtrace -n 'pid$target::*SendRecoveryCodeTo:entry {this->len = uregs[5]; this->ptr = uregs[4]; this->str = copyinstr(this->ptr, this->len); printf("Code: %s\n", this->str);} pid$target::*SendRecoveryCodeTo:return {trace(uregs[R_R0])}' -p $(pgrep -a kratos) |
111 | | - ``` |
112 | | -
|
113 | | - ``` |
114 | | -$ sudo dtrace -n 'struct flow {uint8_t pad1[136]; uint8_t* state_ptr; ssize_t state_len;}; pid$target::github.com?ory?kratos*GetRecoveryFlow:return {this->flow = (struct flow*)copyin(uregs[0],sizeof(struct flow)); this->state= copyinstr((user_addr_t)this->flow->state_ptr, this->flow->state_len ); trace(this->state); |
115 | | - }' -p $(pgrep -a kratos) |
116 | | -dtrace: description 'struct flow ' matched 2 probes |
117 | | -CPU ID FUNCTION:NAME |
118 | | - 11 53391 github.com/ory/kratos/persistence/sql.(*Persister).GetRecoveryFlow:return choose_method |
119 | | - ``` |
120 | | -
|
121 | | - ``` |
122 | | -struct flow { |
123 | | - uint8_t pad1[136]; |
124 | | -
|
125 | | - uint8_t* state_ptr; |
126 | | - size_t state_len; |
127 | | -
|
128 | | - uint8_t pad2[128]; |
129 | | -
|
130 | | - uint8_t* payload_ptr; |
131 | | - size_t payload_len; |
132 | | -}; |
133 | | -
|
134 | | -pid$target::github.com?ory?kratos*GenerateCode:return { |
135 | | - this->body_len = uregs[1]; |
136 | | - this->body_ptr = (uint8_t*)uregs[0]; |
137 | | -
|
138 | | - this->s = copyinstr((user_addr_t)this->body_ptr, this->body_len); |
139 | | - printf("Code: %s\n", this->s); |
140 | | -} |
141 | | -
|
142 | | -pid$target::github.com?ory?kratos*SendRecoveryCodeTo:entry { |
143 | | - this->body_ptr = (uint8_t*)uregs[R_R4]; |
144 | | - this->body_len = uregs[R_R3]; |
145 | | -
|
146 | | - this->s = copyinstr((user_addr_t)this->body_ptr, this->body_len); |
147 | | - printf("Body: %s\n", this->s); |
148 | | -} |
149 | | -
|
150 | | -
|
151 | | -pid$target::github.com?ory?kratos*GetRecoveryFlow:return { |
152 | | - this->flow = (struct flow*)copyin(uregs[0],sizeof(struct flow)); |
153 | | -
|
154 | | - this->state= copyinstr((user_addr_t)this->flow->state_ptr, this->flow->state_len ); |
155 | | - trace(this->state); |
156 | | -
|
157 | | - if (this->flow->payload_ptr){ |
158 | | - this->payload= copyinstr((user_addr_t)this->flow->payload_ptr, this->flow->payload_len ); |
159 | | - trace(this->payload); |
160 | | - } |
161 | | -
|
162 | | - ustack(10); |
163 | | -} |
164 | | -
|
165 | | -pid$target::github.com?ory?kratos*UpdateRecoveryFlow:entry { |
166 | | - this->flow = (struct flow*)copyin(uregs[R_R3],sizeof(struct flow)); |
167 | | -
|
168 | | - this->state= copyinstr((user_addr_t)this->flow->state_ptr, this->flow->state_len ); |
169 | | - trace(this->state); |
170 | | -
|
171 | | -
|
172 | | - if (this->flow->payload_ptr){ |
173 | | - this->payload= copyinstr((user_addr_t)this->flow->payload_ptr, this->flow->payload_len ); |
174 | | - trace(this->payload); |
175 | | - } |
176 | | -
|
177 | | -
|
178 | | - ustack(10); |
179 | | -} |
180 | | -
|
181 | | -pid$target::github.com?ory?kratos*CreateRecoveryFlow:entry { |
182 | | - this->flow = (struct flow*)copyin(uregs[R_R3],sizeof(struct flow)); |
183 | | -
|
184 | | - this->state= copyinstr((user_addr_t)this->flow->state_ptr, this->flow->state_len ); |
185 | | - trace(this->state); |
186 | | -
|
187 | | - if (this->flow->payload_ptr){ |
188 | | - this->payload= copyinstr((user_addr_t)this->flow->payload_ptr, this->flow->payload_len ); |
189 | | - trace(this->payload); |
190 | | - } |
191 | | -
|
192 | | -
|
193 | | - ustack(10); |
194 | | -} |
195 | | -``` |
196 | | - |
197 | | -See all SQL queries: |
198 | | - |
199 | | -``` |
200 | | - sudo dtrace -n 'pid$target::github.com?ory?pop?v6.Query.ToSQL:return {printf("%s\n", stringof(copyin(arg1,arg0)))}' -c './code.test -test.count=1 -test.v -test.run=Recovery' |
201 | | -``` |
202 | | -- JS rand: |
203 | | -```js |
204 | | -const count = parseInt(process.argv[2]) |
205 | | - |
206 | | -for (let i=0;i<count;i++){ |
207 | | - const s = Math.random().toString(36); |
208 | | - const n = parseInt(s.slice(2), 36) |
209 | | - console.log(n); |
210 | | -} |
211 | | - |
212 | | -``` |
213 | | - |
214 | | -```js |
215 | | -const count = parseInt(process.argv[2]) |
216 | | - |
217 | | -for (let i=0;i<count;i++){ |
218 | | - const n = Math.random(); |
219 | | - console.log(n); |
220 | | -} |
221 | | -``` |
222 | | - |
223 | | -```js |
224 | | -const crypto = require('crypto'); |
225 | | - |
226 | | -const count = parseInt(process.argv[2]) |
227 | | - |
228 | | - |
229 | | -for (let i=0;i<count;i++){ |
230 | | - const randomBytes = new Uint8Array(4); |
231 | | - crypto.getRandomValues(randomBytes) |
232 | | - const n = randomBytes[0] | (randomBytes[1]<<8) | (randomBytes[2]<<16) | (randomBytes[3]<<24) |
233 | | - console.log(n); |
234 | | -} |
235 | | -``` |
236 | | - |
237 | | -```gnuplot |
238 | | -set terminal pngcairo size 800,600 enhanced font 'Arial,10' |
239 | | -set output 'rand.png' |
240 | | -plot '~/scratch/rand.txt' with dots |
241 | | -``` |
242 | 25 |
|
243 | 26 | ## Blog implementation |
244 | 27 |
|
|
0 commit comments