You can use pdftex features to record the position before and after a glue node, and then (on the second run) use that information to construct a box of the desired size.
Here paragraph 1 just has glue, paragraph 2 has a box with Z...Z set to the same size.

\newwrite\zz % easier in latex where this is set up already
\openin\zz=\jobname.aux
\ifeof\zz\else
\input \jobname.aux
\closein\zz
\fi
\immediate\openout\zz=\jobname.aux
1) zzz zz zz zz zz zz zz zz zzzz zz zz zz zz zz zz zz z
zzzz%
\hskip 2.4in plus 2fil
zzz zzzz zzz
zzz zz zz zz zz zz zz zz zzzz zz zz zz zz zz zz zz z
zzz zz zz zz zz zz zz zz zzzz zz zz zz zz zz zz zz z
2) zzz zz zz zz zz zz zz zz zzzz zz zz zz zz zz zz zz z
zzzz%
\ifx\zzA\undefined\else
\leavevmode\rlap{\hbox to \dimexpr \zzB sp -\zzA sp{Z\dotfill Z}}%
\pdfsavepos\write\zz{\gdef\string\zzA{\the\pdflastxpos}}%
\hskip 2.4in plus 2fil
\pdfsavepos\write\zz{\gdef\string\zzB{\the\pdflastxpos}}%
zzz zzzz zzz
zzz zz zz zz zz zz zz zz zzzz zz zz zz zz zz zz zz z
zzz zz zz zz zz zz zz zz zzzz zz zz zz zz zz zz zz z
\bye
fil
glue will only be known, once the paragraph is built, i.e. you can set the width of the\hbox
to the width of the glue, if they are in different paragraphs. (However, I don't know whether you can get the size of the glue within TeX, but it's definitely possible in Lua) – Henri Menke Aug 18 '19 at 0:42