totp_faux.yml 73 lignes · 2586 octets
---
# Un essai de force brute sur le second facteur (verify.yml, F-15) : mot de passe juste de
# jean.dupont, puis code TOTP faux (le code courant décalé) ; aucune session n'est ouverte. Si le
# portail bloque déjà la connexion au mot de passe (PE_WAIT, 86), l'essai s'arrête là (bloque).
- name: Force brute — ouvrir le formulaire, essai {{ essai }}
  ansible.builtin.uri:
    url: "{{ portail }}/"
    ca_path: "{{ ca }}"
    return_content: true
  register: formulaire
  until: formulaire.status == 200
  retries: 15
  delay: 2

- name: Force brute — le mot de passe juste mène au choix du second facteur, essai {{ essai }}
  ansible.builtin.uri:
    url: "{{ portail }}/"
    ca_path: "{{ ca }}"
    method: POST
    body_format: form-urlencoded
    body:
      user: "{{ oiam_admin_initial.uid }}"
      password: "{{ jean_nouveau_mdp }}"
      token: "{{ formulaire.content | regex_search(jeton, '\\1') | first }}"
    follow_redirects: none
    return_content: true
  register: choix
  failed_when: >-
    choix.status != 200 or ('action="/2fchoice"' not in choix.content and 'trmsg="86"' not in choix.content)
    or choix.set_cookie | default('') is search(cookie)

- name: Force brute — retenir le blocage, essai {{ essai }}
  ansible.builtin.set_fact:
    bloque: "{{ 'trmsg=\"86\"' in choix.content }}"

- name: Force brute — choisir TOTP, essai {{ essai }}
  when: not bloque
  ansible.builtin.uri:
    url: "{{ portail }}/2fchoice"
    ca_path: "{{ ca }}"
    method: POST
    body_format: form-urlencoded
    body:
      sf: totp
      token: "{{ choix.content | regex_search(jeton, '\\1') | first }}"
    return_content: true
  register: formulaire_totp
  failed_when: formulaire_totp.status != 200 or 'action="/totp2fcheck"' not in formulaire_totp.content

- name: Force brute — calculer le code courant, essai {{ essai }}
  when: not bloque
  ansible.builtin.command:
    cmd: oathtool --totp -b -
    stdin: "{{ cle_totp.json.secret }}"
  register: code_totp
  changed_when: false
  no_log: true

- name: Force brute — un code faux n'ouvre pas de session, essai {{ essai }}
  when: not bloque
  ansible.builtin.uri:
    url: "{{ portail }}/totp2fcheck"
    ca_path: "{{ ca }}"
    method: POST
    body_format: form-urlencoded
    body:
      code: "{{ '%06d' % ((code_totp.stdout | int + 500000) % 1000000) }}"
      token: "{{ formulaire_totp.content | regex_search(jeton, '\\1') | first }}"
    follow_redirects: none
    status_code: [200, 401]
    return_content: true
  register: r
  failed_when: r.set_cookie | default('') is search(cookie)