• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Gallopsled / pwntools / 13600950642

01 Mar 2025 04:10AM UTC coverage: 74.211% (+3.2%) from 71.055%
13600950642

Pull #2546

github

web-flow
Merge 77df40314 into 60cff2437
Pull Request #2546: ssh: Allow passing `disabled_algorithms` keyword argument from `ssh` to paramiko

3812 of 6380 branches covered (59.75%)

0 of 1 new or added line in 1 file covered. (0.0%)

1243 existing lines in 37 files now uncovered.

13352 of 17992 relevant lines covered (74.21%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/pwnlib/commandline/cyclic.py
1
from __future__ import absolute_import
1✔
2
from __future__ import division
1✔
3

4
import argparse
1✔
5
import string
1✔
6
import sys
1✔
7

8
import pwnlib.args
1✔
9
pwnlib.args.free_form = False
1✔
10

11
from pwn import *
1✔
12
from pwnlib.commandline import common
1✔
13

14
parser = common.parser_commands.add_parser(
1✔
15
    'cyclic',
16
    help = "Cyclic pattern creator/finder",
17
    description = "Cyclic pattern creator/finder"
18
)
19

20
parser.add_argument(
1✔
21
    '-a', '--alphabet',
22
    metavar = 'alphabet',
23
    default = string.ascii_lowercase.encode(),
24
    type = packing._encode,
25
    help = 'The alphabet to use in the cyclic pattern (defaults to all lower case letters)',
26
)
27

28
parser.add_argument(
1✔
29
    '-n', '--length',
30
    metavar = 'length',
31
    default = 4,
32
    type = int,
33
    help = 'Size of the unique subsequences (defaults to 4).'
34
)
35

36
parser.add_argument(
1✔
37
    '-c', '--context',
38
    metavar = 'context',
39
    action = 'append',
40
    type   = common.context_arg,
41
    choices = common.choices,
42
    help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
43
)
44

45
group = parser.add_mutually_exclusive_group(required=False)
1✔
46
group.add_argument(
1✔
47
    '-l', '-o', '--offset', '--lookup',
48
    dest = 'lookup',
49
    type = str.encode,
50
    metavar = 'lookup_value',
51
    help = 'Do a lookup instead printing the alphabet',
52
)
53

54
group.add_argument(
1✔
55
    'count',
56
    type=int,
57
    nargs='?',
58
    default=None,
59
    help='Number of characters to print'
60
)
61

62
def main(args):
1✔
63
    alphabet = args.alphabet
1✔
64
    subsize  = args.length
1✔
65

66
    if args.lookup:
1✔
67
        pat = args.lookup
1✔
68

69
        try:
1✔
70
            pat = int(pat, 0)
1✔
71
            pat = pack(pat, 'all')
1✔
UNCOV
72
        except ValueError:
×
UNCOV
73
            pass
×
74
        pat = flat(pat, bytes=args.length)
1✔
75

76
        if len(pat) < subsize:
1!
UNCOV
77
            log.critical('Subpattern must be at least %d bytes' % subsize)
×
UNCOV
78
            sys.exit(1)
×
79
        else:
80
            pat = pat[:subsize]
1✔
81

82
        if not all(c in alphabet for c in pat):
1!
UNCOV
83
            log.critical('Pattern contains characters not present in the alphabet')
×
UNCOV
84
            sys.exit(1)
×
85

86
        offset = cyclic_find(pat, alphabet, subsize)
1✔
87

88
        if offset == -1:
1!
UNCOV
89
            log.critical('Given pattern does not exist in cyclic pattern')
×
UNCOV
90
            sys.exit(1)
×
91
        else:
92
            print(offset)
1✔
93
    else:
94
        want   = args.count
1✔
95
        result = cyclic(want, alphabet, subsize)
1✔
96
        got    = len(result)
1✔
97
        if want is not None and got < want:
1!
UNCOV
98
            log.failure("Alphabet too small (max length = %i)" % got)
×
99

100
        out = getattr(sys.stdout, 'buffer', sys.stdout)
1✔
101
        out.write(result)
1✔
102

103
        if out.isatty():
1!
UNCOV
104
            out.write(b'\n')
×
105

106
if __name__ == '__main__':
1✔
107
    pwnlib.commandline.common.main(__file__, main)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc